diff --git a/bananaIO/src/Gpio.c b/bananaIO/src/Gpio.c index 56de256..a3158e1 100644 --- a/bananaIO/src/Gpio.c +++ b/bananaIO/src/Gpio.c @@ -43,9 +43,9 @@ int ReadPinValue(int pin) { void WritePinValue(int pin, int value) { if(value == LOW) - WriteRegister(CurrentSoc.Register.GpioClear, pin, 1, GPIO_PIN_CLEAR_VALUE); + WriteRegister(CurrentSoc.Register.GpioClear, pin, GPIO_PIN_CLEAR_MASK, GPIO_PIN_CLEAR_VALUE); else - WriteRegister(CurrentSoc.Register.GpioSet, pin, 1, GPIO_PIN_SET_VALUE); + WriteRegister(CurrentSoc.Register.GpioSet, pin, GPIO_PIN_SET_MASK, GPIO_PIN_SET_VALUE); } int digitalRead(int pin) diff --git a/bananaIO/src/RaspberryPi.h b/bananaIO/src/RaspberryPi.h index f7f953c..ace5a0a 100644 --- a/bananaIO/src/RaspberryPi.h +++ b/bananaIO/src/RaspberryPi.h @@ -17,7 +17,10 @@ extern "C" { #endif +#define GPIO_PIN_CLEAR_MASK 0xFFFFFFFF #define GPIO_PIN_CLEAR_VALUE 1 + +#define GPIO_PIN_SET_MASK 0xFFFFFFFF #define GPIO_PIN_SET_VALUE 1 #define SOC_REGISTER_PAGE_SIZE 4096 diff --git a/bananaIO/src/Register.c b/bananaIO/src/Register.c index f2c00ad..df98630 100644 --- a/bananaIO/src/Register.c +++ b/bananaIO/src/Register.c @@ -21,7 +21,7 @@ struct Register *NewRegister(volatile uint32_t *mappedMemory, int portRegister, result->PinsPerPort = SOC_REGISTER_BLOCKSIZE * registerCount * result->PinsPerRegister; result->mappedMemory = mappedMemory; - + return result; } @@ -33,19 +33,17 @@ void WriteRegister(struct Register *reg, int pin, int resetMask, int value) { int registerOffset = pin % reg->PinsPerPort / reg->PinsPerRegister; // debug int offset = portOffset + (reg->PortRegister / SOC_REGISTER_BLOCKSIZE) + registerOffset; - int val; - - val = *(reg->mappedMemory + offset); // debug - *(reg->mappedMemory + offset) &= ~(resetMask << shift); - val = *(reg->mappedMemory + offset); // debug - *(reg->mappedMemory + offset) |= (value << shift); - val = *(reg->mappedMemory + offset); // debug - - + if (resetMask == -1) + *(reg->mappedMemory + offset) = (value << shift); // just set value into address. Raspi Set Register!? + else + { + *(reg->mappedMemory + offset) &= ~(resetMask << shift); // mask + *(reg->mappedMemory + offset) |= (value << shift); // and set + } + } -void SetRegisterBit(struct Register *reg, int pin) -{ +void SetRegisterBit(struct Register *reg, int pin) { int shift = (pin % reg->PinsPerRegister) * reg->BitsPerPin; int port = pin / reg->PinsPerPort; // debug int portOffset = port * (SOC_REGISTER_PORT_SIZE / SOC_REGISTER_BYTE_PER_REGISTER); // debug @@ -105,9 +103,9 @@ void WriteRegister(struct Register *reg, int pin, int resetMask, int value) { int val; val = *(reg->mappedMemory + offset); // debug - *(reg->mappedMemory + offset) &= ~(resetMask << shift); + *(reg->mappedMemory + offset) &= ~(resetMask << shift); val = *(reg->mappedMemory + offset); // debug - *(reg->mappedMemory + offset) |= (value << shift); + *(reg->mappedMemory + offset) |= (value << shift); val = *(reg->mappedMemory + offset); // debug diff --git a/bananaIO/src/SocConfiguration.h b/bananaIO/src/SocConfiguration.h index 893c645..ae74ca8 100644 --- a/bananaIO/src/SocConfiguration.h +++ b/bananaIO/src/SocConfiguration.h @@ -12,7 +12,7 @@ extern "C" { #endif -#define BANANE 1 +//#define BANANE 1 #ifdef __cplusplus