fw: Implement SBC controls

This commit is contained in:
Markus Koch 2020-07-31 19:07:11 +02:00
parent a396052487
commit 6ae88b0101
6 changed files with 51 additions and 5 deletions

View File

@ -14,6 +14,9 @@ void input_init()
PORT_KEYPAD(DDR) &= ~(PIN_KEYPAD_MASK); // Key inputs PORT_KEYPAD(DDR) &= ~(PIN_KEYPAD_MASK); // Key inputs
PORT_KEYPAD(PORT) |= PIN_KEYPAD_MASK; // Key pullups PORT_KEYPAD(PORT) |= PIN_KEYPAD_MASK; // Key pullups
PORT_SBCMON(DDR) &= ~PIN_SBCMON;
PORT_SBCMON(PORT) |= PIN_SBCMON;
} }
inline int8_t get_rotary_delta() inline int8_t get_rotary_delta()
@ -97,6 +100,11 @@ inline void input_clear_events()
sw_event = 0; sw_event = 0;
} }
inline uint8_t get_sbc_state()
{
return !(PORT_SBCMON(PIN) & PIN_SBCMON);
}
// Need to call timer_proc() before calling this function! // Need to call timer_proc() before calling this function!
void input_proc() void input_proc()
{ {

View File

@ -6,6 +6,9 @@
#define PORT_KEYAUX(t) t##B #define PORT_KEYAUX(t) t##B
#define PIN_ROTARY_PUSH (1 << 0) #define PIN_ROTARY_PUSH (1 << 0)
#define PORT_SBCMON(t) t##C
#define PIN_SBCMON (1 << 1)
#define PORT_ROTARY(t) t##D #define PORT_ROTARY(t) t##D
#define PIN_ROTARY_A (1 << 3) // INT1 #define PIN_ROTARY_A (1 << 3) // INT1
#define PIN_ROTARY_B (1 << 4) #define PIN_ROTARY_B (1 << 4)
@ -15,6 +18,6 @@ void input_proc();
int8_t get_rotary_delta(); int8_t get_rotary_delta();
uint8_t get_switch_event(); uint8_t get_switch_event();
void input_clear_events(); void input_clear_events();
extern uint8_t ctime; uint8_t get_sbc_state();
#endif // INPUT_H #endif // INPUT_H

View File

@ -8,6 +8,8 @@
#include "batmon.h" #include "batmon.h"
#include "pm.h" #include "pm.h"
#define TIME_POWEROFF 5000
#define PORT_SPI(t) t##B #define PORT_SPI(t) t##B
#define PIN_SPI_CS (1 << 2) #define PIN_SPI_CS (1 << 2)
@ -92,6 +94,7 @@ int main()
suspend(); suspend();
pm_init();
lcd_init(LCD_DISP_ON); lcd_init(LCD_DISP_ON);
lcd_title(PSTR("Starting IOC Rev."), PSTR(GITREV)); lcd_title(PSTR("Starting IOC Rev."), PSTR(GITREV));
spi_init(); spi_init();
@ -104,9 +107,12 @@ int main()
reset(); reset();
} }
lcd_title(PSTR("Starting up."), PSTR("Please wait...")); lcd_title(PSTR("Starting up."), PSTR("Please wait."));
pm_sbc_on();
_delay_ms(10); _delay_ms(10);
while (!get_sbc_state());
lcd_title(PSTR("Starting up."), PSTR("Please wait..."));
while (1) { while (1) {
if (!spi_proc()) { if (!spi_proc()) {
@ -117,10 +123,15 @@ int main()
case 1: case 1:
input_proc(); input_proc();
break; break;
case 2:
if (get_sbc_state())
timer_set(TIMID_POWEROFF, MS_TO_TICKS(TIME_POWEROFF));
if (timer_expired(TIMID_POWEROFF))
reset();
} }
} }
sched = sched + 1; sched = sched + 1;
if (sched == 4) { if (sched == 5) {
sched = 0; sched = 0;
if (batmon_proc()) if (batmon_proc())
reset(); reset();

View File

@ -66,3 +66,19 @@ char* post()
return 0; return 0;
} }
void pm_init()
{
PORT_SBCPOW(DDR) |= PIN_SBCPOW;
pm_sbc_off();
}
void pm_sbc_on()
{
PORT_SBCPOW(PORT) |= PIN_SBCPOW;
}
void pm_sbc_off()
{
PORT_SBCPOW(PORT) &= ~PIN_SBCPOW;
}

View File

@ -2,7 +2,14 @@
#define PM_H #define PM_H
#include <avr/io.h> #include <avr/io.h>
#define PORT_SBCPOW(t) t##C
#define PIN_SBCPOW (1 << 2)
void pm_init();
void suspend(); void suspend();
char* post(); char* post();
void pm_init();
void pm_sbc_on();
void pm_sbc_off();
#endif // PM_H #endif // PM_H

View File

@ -4,7 +4,8 @@
#define TIMID_SW_DEBOUNCE 0 #define TIMID_SW_DEBOUNCE 0
#define TIMID_SW_LONGPRESS 1 #define TIMID_SW_LONGPRESS 1
#define NTIM 2 #define TIMID_POWEROFF 2
#define NTIM 3
#define MS_TO_TICKS(ms) (((ms/1000 * F_CPU/1024) / 256)) #define MS_TO_TICKS(ms) (((ms/1000 * F_CPU/1024) / 256))