Skip to content

Commit

Permalink
Code cleanup; minimal Rebol version 3.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Nov 25, 2022
1 parent 3f490c2 commit de5e390
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 106 deletions.
6 changes: 3 additions & 3 deletions src/bcm2835-rebol-extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "common.h"

#define MIN_REBOL_VER 3
#define MIN_REBOL_REV 5
#define MIN_REBOL_UPD 4
#define MIN_REBOL_REV 9
#define MIN_REBOL_UPD 0
#define VERSION(a, b, c) (a << 16) + (b << 8) + c
#define MIN_REBOL_VERSION VERSION(MIN_REBOL_VER, MIN_REBOL_REV, MIN_REBOL_UPD)

Expand Down Expand Up @@ -161,7 +161,7 @@ typedef int (*MyCommandPointer)(RXIFRM *frm, void *ctx);
"spi_transfer: command [{Transfers one byte to and from the currently selected SPI slave. Asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) during the transfer. Clocks the 8 bit value out on MOSI, and simultaneously clocks in data from MISO. Returns the read data byte from the slave.} value [integer! char! binary!] \"The 8 bit data byte to write to MOSI, or buffer\"]\n"\
"spi_write: command [{Transfers any number of bytes to the currently selected SPI slave.} data [binary! integer! char!] {Buffer of bytes to send or the 8 bit data byte to write to MOSI}]\n"\
"version: command [\"Returns the bcm2835 version.\"]\n"\
"set_debug: command [state [logic! integer!]]\n"\
"set_debug: command [{Prevents access to the kernel memory, and does not do any peripheral access. Instead it prints out what it _would_ do if debug were 0.} state [logic! integer!]]\n"\
"delay: command [\"Delays for the specified number of milliseconds.\" millis [integer!] \"Delay in milliseconds\"]\n"\
"delayMicroseconds: command [\"Delays for the specified number of microseconds\" micros [integer!] \"Delay in microseconds\"]\n"\
"protect/hide 'init-words\n"\
Expand Down
6 changes: 3 additions & 3 deletions src/bcm2835-rebol-extension.r3
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REBOL [
title: "bcm2835 module builder"
title: "BCM2835 module builder"
type: module
]

Expand Down Expand Up @@ -391,8 +391,8 @@ append out reword {//
#include "common.h"
#define MIN_REBOL_VER 3
#define MIN_REBOL_REV 5
#define MIN_REBOL_UPD 4
#define MIN_REBOL_REV 9
#define MIN_REBOL_UPD 0
#define VERSION(a, b, c) (a << 16) + (b << 8) + c
#define MIN_REBOL_VERSION VERSION(MIN_REBOL_VER, MIN_REBOL_REV, MIN_REBOL_UPD)
Expand Down
101 changes: 1 addition & 100 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Test Rebol extension
// BCM2835 Rebol extension
// ====================================
// Use on your own risc!

Expand All @@ -18,102 +18,3 @@
#define debug_print(fmt, ...)
#define trace(str)
#endif

#define DOUBLE_BUFFER_SIZE 16
#define ARG_BUFFER_SIZE 8

#ifdef __cplusplus
typedef struct ctx_trackbar {
int value;
cv::String *name;
cv::String *window;
RXICBI *cbi;
RXIARG *args;
} CTX_TRACKBAR;
#else
typedef struct ctx_trackbar {
int value;
void* name;
void* window;
RXICBI *cbi;
RXIARG *args;
} CTX_TRACKBAR;
#endif


REBOOL fetch_word (REBSER *cmds, REBCNT index, u32* words, REBCNT *cmd);
REBOOL fetch_mode (REBSER *cmds, REBCNT index, REBCNT *result, REBCNT start, REBCNT max);
REBOOL fetch_color(REBSER *cmds, REBCNT index, REBCNT *cmd);



extern u32* ext_cmd_words;
extern u32* ext_arg_words;
extern REBDEC doubles[DOUBLE_BUFFER_SIZE];
extern RXIARG arg[ARG_BUFFER_SIZE];


//==============================================================//
// Some useful defines which are actually not used in the test //
//==============================================================//

#define PI 3.14159265358979323846264338327950288

#define TO_RADIANS(value) ((value) *= PI / 180.0)

#define TUPLE_TO_COLOR(t) (REBCNT)((t.bytes[0]==3?255:t.bytes[4])<<24 | (t.bytes[1])<<16 | (t.bytes[2])<<8 | (t.bytes[3]))

#define FETCH_3_PAIRS(c,i, a1, a2, a3) (\
RXT_PAIR == RL_GET_VALUE(c, i, &a1) \
&& RXT_PAIR == RL_GET_VALUE(c, i+1, &a2) \
&& RXT_PAIR == RL_GET_VALUE(c, i+2, &a3))

#define RESOLVE_ARG(a) type = RL_GET_VALUE_RESOLVED(cmds, index++, &arg[a]);

#define RESOLVE_PAIR_ARG(a, d) RESOLVE_ARG(a) \
if (type != RXT_PAIR) goto error; \
doubles[d] = arg[a].pair.x; \
doubles[d+1] = arg[a].pair.y;

#define RESOLVE_PAIR_ARG_OPTIONAL(a, d) RESOLVE_ARG(a) \
if (type == RXT_PAIR) { \
doubles[d] = arg[a].pair.x; \
doubles[d+1] = arg[a].pair.y; \
} else { type = NULL; index--; }

#define RESOLVE_INT_ARG(a) RESOLVE_ARG(a) \
if (type != RXT_INTEGER) goto error;

#define RESOLVE_INT_ARG_OPTIONAL(a) RESOLVE_ARG(a) \
if (type != RXT_INTEGER) {type = NULL; index--; }

#define RESOLVE_NUMBER_ARG(a, d) RESOLVE_ARG(a) \
if (type == RXT_DECIMAL || type == RXT_PERCENT) doubles[d] = arg[a].dec64; \
else if (type == RXT_INTEGER) doubles[d] = (double)arg[a].int64; \
else goto error;

#define RESOLVE_NUMBER_ARG_OPTIONAL(a, d) RESOLVE_ARG(a) \
if (type == RXT_DECIMAL || type == RXT_PERCENT) doubles[d] = arg[a].dec64; \
else if (type == RXT_INTEGER) doubles[d] = (double)arg[a].int64; \
else { type = NULL; index--;}

#define RESOLVE_NUMBER_OR_PAIR_ARG(a, d) RESOLVE_ARG(a) \
if (type == RXT_DECIMAL || type == RXT_PERCENT) doubles[d] = doubles[d+1] = arg[a].dec64; \
else if (type == RXT_INTEGER) doubles[d] = doubles[d+1] = (double)arg[a].int64; \
else if (type == RXT_PAIR) {\
doubles[d] = arg[a].pair.x; \
doubles[d+1] = arg[a].pair.y; \
} else goto error;

#define RESOLVE_STRING_ARG(a) RESOLVE_ARG(a) \
if (type != RXT_STRING) goto error;

#define GET_PAIR(a, d) RESOLVE_ARG(a) \
if (type != RXT_PAIR) goto error; \
doubles[d] = arg[a].pair.x; \
doubles[d+1] = arg[a].pair.y;

#define ARG_X(n) (arg[n].pair.x)
#define ARG_Y(n) (arg[n].pair.y)

#define OPT_WORD_FLAG(flag, name) if (fetch_word(cmds, index, ext_arg_words, &cmd) && cmd == name) { flag = TRUE; index++; }

0 comments on commit de5e390

Please sign in to comment.