diff --git a/src/energenie/drv/gpio.h b/src/energenie/drv/gpio.h index 7437e9a..6226a1a 100644 --- a/src/energenie/drv/gpio.h +++ b/src/energenie/drv/gpio.h @@ -10,13 +10,14 @@ /***** FUNCTION PROTOTYPES *****/ void gpio_init(void); -void gpio_setin(int g); -void gpio_setout(int g); -void gpio_high(int g); -void gpio_low(int g); -void gpio_write(int g, int v); -int gpio_read(int g); -//TODO probably need gpio_finished() to unmmap() the memory region and clean up the peripheral? +void gpio_setin(uint8_t g); +void gpio_setout(uint8_t g); +void gpio_high(uint8_t g); +void gpio_low(uint8_t g); +void gpio_write(uint8_t g, uint8_t v); +int gpio_read(uint8_t g); +void gpio_finished(void); + #endif /***** END OF FILE *****/ diff --git a/src/energenie/drv/gpio_arduino.c b/src/energenie/drv/gpio_arduino.c index 589e77c..ac0a6de 100644 --- a/src/energenie/drv/gpio_arduino.c +++ b/src/energenie/drv/gpio_arduino.c @@ -12,7 +12,39 @@ * boards in the future. */ -//TODO GPIO_SIMULATED can be replaced with gpio_sim.c in future +#else if defined(ARDUINO) +#if defined(ARDUINO_PROMICRO) + +//TODO: there might be platform specific macros here to +//extract register address and bitmask +//really, what we want is to be able to pass in a uint8_t which is a GPIO number +//and this get converted (at compile time preferably) into the register access code +//required to read/write and configure that bit. The actual mapping shoudl probably +//be in the C code for gpio_arduino + +//something a bit like this, but this is not correct yet +//#define GPIO_0 PORTB,0x01 +//#define GPIO_1 PORTB,0x02 +//#define GPIO_2 PORTB,0x04 +//#define GPIO_3 PORTB,0x08 +//#define GPIO_4 PORTB,0x10 +//#define GPIO_5 PORTB,0x20 +//#define GPIO_6 PORTB,0x40 +//#define GPIO_7 PORTB,0x90 +//#define GPIO_8 PORTC,0x01 +//#define GPIO_9 PORTC,0x02 +//#define GPIO_10 PORTC,0x04 +//#define GPIO_14 PORTC,0x08 +//#define GPIO_15 PORTC,0x10 +//#define GPIO_16 PORTC,0x20 + +#else +//#error Unknown Arduino platform +#endif +#else +//#error Unknown platform +#endif + /***** INCLUDES *****/ diff --git a/src/energenie/drv/gpio_rpi.c b/src/energenie/drv/gpio_rpi.c index ce0cd6e..07348d5 100644 --- a/src/energenie/drv/gpio_rpi.c +++ b/src/energenie/drv/gpio_rpi.c @@ -146,4 +146,10 @@ } +void gpio_finished(void) +{ + //TODO probably need gpio_finished() to unmmap() the memory region and clean up the peripheral? +} + + /***** END OF FILE *****/ diff --git a/src/energenie/drv/gpio_sim.c b/src/energenie/drv/gpio_sim.c index de2c2d7..fc89aef 100644 --- a/src/energenie/drv/gpio_sim.c +++ b/src/energenie/drv/gpio_sim.c @@ -1,38 +1,35 @@ /* gpio_sim.c D.J.Whale 04/04/2016 * - * A very simple interface to a simulated GPIO port with no platform dependencies. + * A very simple interface to a simulated GPIO port with minimal platform dependencies. */ /***** INCLUDES *****/ -#include -//#include - +#include // OPTIONAL #include "gpio.h" /***** CONFIGURATION *****/ +#define GPIO_MAX 20 +#define GPIO_DEBUG +//#define GPIO_LOOPBACK -/***** CONSTANTS *****/ + +/* Printf is not available on some platforms, or not very efficient. + * These macros make it possible to re-map I/O to more efficient functions. + */ + +#define OUTS(s) printf("%s", s) +#define OUTN(n) printf("%d", (unsigned int)d) +#define OUTC(c) putch(c) +#define NL() OUTC('\n') /***** VARIABLES *****/ - -/****** MACROS *****/ - -//#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) -//#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) -//#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) - -//#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0 -//#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 - -//#define GPIO_READ(g) ((*(gpio+13)&(1<