aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--boards/OLIMEX_AVR_MT_128/board.h35
-rw-r--r--demos/AVR-ATmega128-GCC/lcd.c26
-rw-r--r--demos/AVR-ATmega128-GCC/main.c6
3 files changed, 37 insertions, 30 deletions
diff --git a/boards/OLIMEX_AVR_MT_128/board.h b/boards/OLIMEX_AVR_MT_128/board.h
index dfe6828bb..4dc68db92 100644
--- a/boards/OLIMEX_AVR_MT_128/board.h
+++ b/boards/OLIMEX_AVR_MT_128/board.h
@@ -93,23 +93,24 @@
#define VAL_DDRG 0x00
#define VAL_PORTG 0x07
-#define PORTA_BUTTON1 (1 << 0)
-#define PORTA_BUTTON2 (1 << 1)
-#define PORTA_BUTTON3 (1 << 2)
-#define PORTA_BUTTON4 (1 << 3)
-#define PORTA_BUTTON5 (1 << 4)
-#define PORTA_DALLAS (1 << 5)
-#define PORTA_RELAY (1 << 6)
-
-#define PORTC_44780_RS (1 << 0)
-#define PORTC_44780_RW (1 << 1)
-#define PORTC_44780_E (1 << 2)
-#define PORTC_44780_D4 (1 << 4)
-#define PORTC_44780_D5 (1 << 5)
-#define PORTC_44780_D6 (1 << 6)
-#define PORTC_44780_D7 (1 << 7)
-#define PORTC_44780_DATA (PORTC_44780_D4 | PORTC_44780_D5 | \
- PORTC_44780_D6 | PORTC_44780_D7)
+
+#define PORTA_BUTTON1 0
+#define PORTA_BUTTON2 1
+#define PORTA_BUTTON3 2
+#define PORTA_BUTTON4 3
+#define PORTA_BUTTON5 4
+#define PORTA_DALLAS 5
+#define PORTA_RELAY 6
+
+#define PORTC_44780_RS_MASK (1 << 0)
+#define PORTC_44780_RW_MASK (1 << 1)
+#define PORTC_44780_E_MASK (1 << 2)
+#define PORTC_44780_D4_MASK (1 << 4)
+#define PORTC_44780_D5_MASK (1 << 5)
+#define PORTC_44780_D6_MASK (1 << 6)
+#define PORTC_44780_D7_MASK (1 << 7)
+#define PORTC_44780_DATA_MASK (PORTC_44780_D4_MASK | PORTC_44780_D5_MASK | \
+ PORTC_44780_D6_MASK | PORTC_44780_D7_MASK)
#define PORTE_BUZZ1 (1 << 4)
#define PORTE_BUZZ2 (1 << 5)
diff --git a/demos/AVR-ATmega128-GCC/lcd.c b/demos/AVR-ATmega128-GCC/lcd.c
index 5ef8fca02..cd8aa5006 100644
--- a/demos/AVR-ATmega128-GCC/lcd.c
+++ b/demos/AVR-ATmega128-GCC/lcd.c
@@ -25,10 +25,10 @@
static void e_pulse(void) {
volatile uint8_t i;
- PORTC |= PORTC_44780_E;
+ PORTC |= PORTC_44780_E_MASK;
for (i = 0; i < ELOOPVALUE; i++);
;
- PORTC &= ~PORTC_44780_E;
+ PORTC &= ~PORTC_44780_E_MASK;
}
static void wait_not_busy(void) {
@@ -41,8 +41,9 @@ static void wait_not_busy(void) {
*/
void lcdInit(void) {
- PORTC = (PORTC & ~(PORTC_44780_DATA | PORTC_44780_RS | PORTC_44780_E | PORTC_44780_RW)) |
- (LCD_CMD_INIT8 & PORTC_44780_DATA);
+ PORTC = (PORTC & ~(PORTC_44780_DATA_MASK | PORTC_44780_RS_MASK |
+ PORTC_44780_E_MASK | PORTC_44780_RW_MASK)) |
+ (LCD_CMD_INIT8 & PORTC_44780_DATA_MASK);
chThdSleep(50);
e_pulse();
chThdSleep(10);
@@ -50,8 +51,9 @@ void lcdInit(void) {
chThdSleep(2);
e_pulse();
wait_not_busy();
- PORTC = (PORTC & ~(PORTC_44780_DATA | PORTC_44780_RS | PORTC_44780_E | PORTC_44780_RW)) |
- (LCD_CMD_INIT4 & PORTC_44780_DATA);
+ PORTC = (PORTC & ~(PORTC_44780_DATA_MASK | PORTC_44780_RS_MASK |
+ PORTC_44780_E_MASK | PORTC_44780_RW_MASK)) |
+ (LCD_CMD_INIT4 & PORTC_44780_DATA_MASK);
e_pulse();
lcdCmd(LCD_CMD_INIT4);
lcdCmd(LCD_SET_DM | LCD_DM_DISPLAY_ON);
@@ -64,9 +66,11 @@ void lcdInit(void) {
void lcdCmd(uint8_t cmd) {
wait_not_busy();
- PORTC = (PORTC | PORTC_44780_DATA) & (cmd | (0x0F & ~PORTC_44780_RS));
+ PORTC = (PORTC | PORTC_44780_DATA_MASK) & (cmd |
+ (0x0F & ~PORTC_44780_RS_MASK));
e_pulse();
- PORTC = (PORTC | PORTC_44780_DATA) & ((cmd << 4) | (0x0F & ~PORTC_44780_RS));
+ PORTC = (PORTC | PORTC_44780_DATA_MASK) & ((cmd << 4) |
+ (0x0F & ~PORTC_44780_RS_MASK));
e_pulse();
}
@@ -78,9 +82,11 @@ void lcdPutc(char c) {
wait_not_busy();
b = c | 0x0F;
- PORTC = (PORTC | PORTC_44780_DATA | PORTC_44780_RS) & (c | 0x0F);
+ PORTC = (PORTC | PORTC_44780_DATA_MASK | PORTC_44780_RS_MASK) &
+ (c | 0x0F);
e_pulse();
- PORTC = (PORTC | PORTC_44780_DATA | PORTC_44780_RS) & ((c << 4) | 0x0F);
+ PORTC = (PORTC | PORTC_44780_DATA_MASK | PORTC_44780_RS_MASK) &
+ ((c << 4) | 0x0F);
e_pulse();
}
diff --git a/demos/AVR-ATmega128-GCC/main.c b/demos/AVR-ATmega128-GCC/main.c
index 0b26a9641..cd982d1b9 100644
--- a/demos/AVR-ATmega128-GCC/main.c
+++ b/demos/AVR-ATmega128-GCC/main.c
@@ -28,8 +28,8 @@ static WORKING_AREA(waThread1, 32);
static msg_t Thread1(void *arg) {
while (TRUE) {
- if (!(PINA & PORTA_BUTTON2))
- PORTA ^= PORTA_RELAY;
+ if (!palReadPad(IOPORT1, PORTA_BUTTON2))
+ palTogglePad(IOPORT1, PORTA_RELAY);
chThdSleepMilliseconds(1000);
}
return 0;
@@ -38,7 +38,7 @@ static msg_t Thread1(void *arg) {
static void TimerHandler(eventid_t id) {
msg_t TestThread(void *p);
- if (!(PINA & PORTA_BUTTON1))
+ if (!palReadPad(IOPORT1, PORTA_BUTTON1))
TestThread(&SD2);
}