Introduce CPP macros for AVR IN/OUT registers
This commit is contained in:
@@ -6,4 +6,12 @@
|
||||
#define __PROJ_DATE__ "2020"
|
||||
#define __PROJ_REV__ "rev:1.0"
|
||||
|
||||
#define R_PORT(P) __R_PORT(P)
|
||||
#define R_DDR(P) __R_DDR(P)
|
||||
#define R_PIN(P) __R_PIN(P)
|
||||
|
||||
#define __R_PORT(P) (PORT ## P)
|
||||
#define __R_DDR(P) (DDR ## P)
|
||||
#define __R_PIN(P) (PIN ## P)
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <avr/io.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "keyboard.h"
|
||||
#include "debounce.h"
|
||||
@@ -31,14 +32,14 @@ void inc_brightness(void)
|
||||
|
||||
void kbd_init(void)
|
||||
{
|
||||
KEYBOARD_DIR &= ~(KEY_INC_HOUR | KEY_INC_MINUTE | KEY_INC_SECOND | KEY_INC_BRIGHTNESS);
|
||||
PORTB |= KEY_INC_HOUR | KEY_INC_MINUTE | KEY_INC_SECOND | KEY_INC_BRIGHTNESS;
|
||||
R_DDR(KEYBOARD_PORT) &= ~(1<<KEY_INC_HOUR | 1<<KEY_INC_MINUTE | 1<<KEY_INC_SECOND | 1<<KEY_INC_BRIGHTNESS);
|
||||
R_PORT(KEYBOARD_PORT) |= 1<<KEY_INC_HOUR | 1<<KEY_INC_MINUTE | 1<<KEY_INC_SECOND | 1<<KEY_INC_BRIGHTNESS;
|
||||
}
|
||||
|
||||
void kbd_handle_event(void)
|
||||
{
|
||||
SuperDebounce(&k_inc_hour, &KEYBOARD_PIN, KEY_INC_HOUR, 20, 0, &inc_hour, 0);
|
||||
SuperDebounce(&k_inc_minute, &KEYBOARD_PIN, KEY_INC_MINUTE, 20, 0, &inc_minute, 0);
|
||||
SuperDebounce(&k_inc_second, &KEYBOARD_PIN, KEY_INC_SECOND, 20, 0, &inc_second, 0);
|
||||
SuperDebounce(&k_inc_brightness, &KEYBOARD_PIN, KEY_INC_BRIGHTNESS, 20, 0, &inc_brightness, 0);
|
||||
SuperDebounce(&k_inc_hour, &R_PIN(KEYBOARD_PORT), 1<<KEY_INC_HOUR, 20, 0, &inc_hour, 0);
|
||||
SuperDebounce(&k_inc_minute, &R_PIN(KEYBOARD_PORT), 1<<KEY_INC_MINUTE, 20, 0, &inc_minute, 0);
|
||||
SuperDebounce(&k_inc_second, &R_PIN(KEYBOARD_PORT), 1<<KEY_INC_SECOND, 20, 0, &inc_second, 0);
|
||||
SuperDebounce(&k_inc_brightness, &R_PIN(KEYBOARD_PORT), 1<<KEY_INC_BRIGHTNESS, 20, 0, &inc_brightness, 0);
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
#ifndef __KEYBOARD_H__
|
||||
#define __KEYBOARD_H__
|
||||
|
||||
#define KEYBOARD_DIR DDRB
|
||||
#define KEYBOARD_PIN PINB
|
||||
#define KEYBOARD_PORT PORTB
|
||||
#define KEY_INC_HOUR (1<<PB0)
|
||||
#define KEY_INC_MINUTE (1<<PB1)
|
||||
#define KEY_INC_SECOND (1<<PB2)
|
||||
#define KEY_INC_BRIGHTNESS (1<<PB3)
|
||||
#define KEYBOARD_PORT B
|
||||
#define KEY_INC_HOUR 0
|
||||
#define KEY_INC_MINUTE 1
|
||||
#define KEY_INC_SECOND 2
|
||||
#define KEY_INC_BRIGHTNESS 3
|
||||
|
||||
void kbd_init(void);
|
||||
void kbd_handle_event(void);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "led.h"
|
||||
|
||||
@@ -10,12 +11,12 @@ static struct LED_DIGS display;
|
||||
void led_init(void)
|
||||
{
|
||||
// Set outputs
|
||||
ANODES_DIR |= DIG0_ANODE | DIG1_ANODE | DIG2_ANODE;
|
||||
LED_DIR |= 0x3F; // 0b00111111
|
||||
R_DDR(ANODES_PORT) |= 1<<DIG0_ANODE | 1<<DIG1_ANODE | 1<<DIG2_ANODE;
|
||||
R_DDR(LED_PORT) |= 0x3F; // 0b00111111
|
||||
|
||||
// Clear LEDs
|
||||
ANODES_PORT = DIG0_ANODE | DIG1_ANODE | DIG2_ANODE;
|
||||
LED_PORT |= 0x3F; // 0b00111111
|
||||
R_PORT(ANODES_PORT) = 1<<DIG0_ANODE | 1<<DIG1_ANODE | 1<<DIG2_ANODE;
|
||||
R_PORT(LED_PORT) |= 0x3F; // 0b00111111
|
||||
|
||||
TCCR0 |= (1<<CS00);
|
||||
TIMSK |= (1<<TOIE0);
|
||||
@@ -41,16 +42,16 @@ ISR(TIMER0_OVF_vect)
|
||||
switch(curr_anode)
|
||||
{
|
||||
case 1:
|
||||
LED_PORT = ~display.dig0;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~DIG0_ANODE : 0xFF;
|
||||
R_PORT(LED_PORT) = ~display.dig0;
|
||||
R_PORT(ANODES_PORT) = led_btnes >= pwm_counter ? ~(1<<DIG0_ANODE) : 0xFF;
|
||||
break;
|
||||
case 2:
|
||||
LED_PORT = ~display.dig1;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~DIG1_ANODE : 0xFF;
|
||||
R_PORT(LED_PORT) = ~display.dig1;
|
||||
R_PORT(ANODES_PORT) = led_btnes >= pwm_counter ? ~(1<<DIG1_ANODE) : 0xFF;
|
||||
break;
|
||||
case 4:
|
||||
LED_PORT = ~display.dig2;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~DIG2_ANODE : 0xFF;
|
||||
R_PORT(LED_PORT) = ~display.dig2;
|
||||
R_PORT(ANODES_PORT) = led_btnes >= pwm_counter ? ~(1<<DIG2_ANODE) : 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#ifndef __LED_H__
|
||||
#define __LED_H__
|
||||
|
||||
#define LED_PORT PORTA
|
||||
#define LED_DIR DDRA
|
||||
#define LED_PORT A
|
||||
|
||||
#define ANODES_PORT PORTD
|
||||
#define ANODES_DIR DDRD
|
||||
#define DIG0_ANODE (1<<PD5)
|
||||
#define DIG1_ANODE (1<<PD6)
|
||||
#define DIG2_ANODE (1<<PD7)
|
||||
#define ANODES_PORT D
|
||||
#define DIG0_ANODE 5
|
||||
#define DIG1_ANODE 6
|
||||
#define DIG2_ANODE 7
|
||||
|
||||
struct LED_DIGS
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/io.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
#include "rtc.h"
|
||||
#include "i2c.h"
|
||||
|
||||
@@ -21,8 +22,8 @@ void rtc_invoke_handler(void);
|
||||
void rtc_int0_init(void)
|
||||
{
|
||||
MCUCR |= (1<<ISC01);
|
||||
INT0_DIR &= ~(1<<INT0_PIN);
|
||||
INT0_PORT |= (1<<INT0_PIN);
|
||||
R_DDR(INT0_PORT) &= ~(1<<INT0_IN);
|
||||
R_PORT(INT0_PORT) |= (1<<INT0_IN);
|
||||
|
||||
rtc_invoke_handler();
|
||||
}
|
||||
|
||||
@@ -7,12 +7,8 @@
|
||||
|
||||
#define DATE_SEPARATOR '.'
|
||||
|
||||
#define INT0_PORT PORTD
|
||||
#define INT0_DIR DDRD
|
||||
#define INT0_PIN PD2
|
||||
#define INT1_PORT PORTD
|
||||
#define INT1_DIR DDRD
|
||||
#define INT1_PIN PD3
|
||||
#define INT0_PORT D
|
||||
#define INT0_IN 2
|
||||
|
||||
#define SECOND 0x02
|
||||
#define MINUTE 0x03
|
||||
|
||||
Reference in New Issue
Block a user