diff --git a/adc.c b/adc.cpp similarity index 100% rename from adc.c rename to adc.cpp diff --git a/avr.c b/avr.cpp similarity index 54% rename from avr.c rename to avr.cpp index ac303d0..a5194a4 100644 --- a/avr.c +++ b/avr.cpp @@ -1,4 +1,5 @@ #include "avr.h" +#include "adc.h" #include "util.h" void setMotorSpeed(MOTOR *motor, int speed) { @@ -14,3 +15,20 @@ void setMotorSpeed(MOTOR *motor, int speed) { *motor->pwmPort = CLAMP(0, ABS(speed), 255); } + +int getButton() { + uint16_t val = getADCValue(7); + + if(val < 144) return 5; + if(val < 228) return 4; + if(val < 304) return 3; + if(val < 376) return 2; + if(val < 600) return 1; + + return 0; +} + +void waitForButton(int i) { + while(getButton() != CLAMP(0, i, 5)); + while(getButton() != 0); +} diff --git a/avr.h b/avr.h index 3727bdf..2d13616 100644 --- a/avr.h +++ b/avr.h @@ -13,4 +13,7 @@ typedef struct { void setMotorSpeed(MOTOR *motor, int speed); +int getButton(); +void waitForButton(int i); + #endif diff --git a/hardware.c b/hardware.c deleted file mode 100644 index 6bc329e..0000000 --- a/hardware.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "hardware.h" - - -void initHardware() { - -} diff --git a/hardware.cpp b/hardware.cpp new file mode 100644 index 0000000..41c7ea2 --- /dev/null +++ b/hardware.cpp @@ -0,0 +1,28 @@ +#include "hardware.h" +#include "adc.h" +#include "i2c.h" + + +void initHardware() { + DDRA = 0x00; + PORTA = 0xFF; + + DDRB = 0xFF; + PORTB = 0x00; + + DDRC = 0x7C; + PORTC = 0x83; + + DDRD = 0xFF; + PORTC = 0x00; + + TCCR0 = 0x62; + TCCR1A = 0xA1; + TCCR1B = 0x82; + OCR0 = 0; + OCR1A = 0; + OCR1B = 0; + + initADC(); + initI2C(); +} diff --git a/i2c.cpp b/i2c.cpp new file mode 100644 index 0000000..61450fa --- /dev/null +++ b/i2c.cpp @@ -0,0 +1,148 @@ +#include "i2c.h" + +#include + + +static bool I2CStartSend(uint8_t addr); +static bool I2CStartRecv(uint8_t addr); +static void I2CStop(); + + +static bool I2CStartSend(uint8_t addr) { + TWCR = (1< + + +void initI2C(); +bool I2CSendByte(uint8_t addr, uint8_t data); +bool I2CSend(uint8_t addr, uint8_t *data, int length); +bool I2CRecvByte(uint8_t addr, uint8_t *data); +int I2CRecv(uint8_t addr, uint8_t *data, int length); + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..2a3f761 --- /dev/null +++ b/main.cpp @@ -0,0 +1,5 @@ +int main() { + + + return 0; +}