Commit 7ff5495a authored by Robey Pointer's avatar Robey Pointer
Browse files

add the remaining things back to the menu

parent 18727a0a
......@@ -56,22 +56,18 @@ static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
{
.Config =
{
USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = {
.Config = {
.InterfaceNumber = INTERFACE_ID_Keyboard,
.ReportINEndpoint =
{
.ReportINEndpoint = {
.Address = KEYBOARD_EPADDR,
.Size = KEYBOARD_EPSIZE,
.Banks = 1,
},
},
.PrevReportINBuffer = PrevKeyboardHIDReportBuffer,
.PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer),
},
};
},
};
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
......@@ -85,7 +81,7 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
#define MATRIX_BITS ((MATRIX_ROWS * MATRIX_COLUMNS + 7) >> 3)
uint8_t matrix[MATRIX_ROWS * MATRIX_COLUMNS] = {
KEY_ESCAPE, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, HID_KEYBOARD_SC_EXSEL, HID_KEYBOARD_SC_EXSEL,
KEY_ESCAPE, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_CIRCLE, KEY_CIRCLE,
KEY_GRAVE_ACCENT_AND_TILDE, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, KEY_MINUS_AND_UNDERSCORE, KEY_EQUAL_AND_PLUS, KEY_BACKSPACE, 0,
......@@ -105,12 +101,12 @@ uint8_t matrix[MATRIX_ROWS * MATRIX_COLUMNS] = {
int low_battery_alert = 0;
static void remote_check_for_low_battery(void) {
int was_low = low_battery_alert;
int was_low = low_battery_alert;
low_battery_alert = controller_battery_is_low();
if (was_low && !low_battery_alert) {
display_clear();
display_flush();
}
if (was_low && !low_battery_alert) {
display_clear();
display_flush();
}
}
......@@ -129,18 +125,18 @@ void kbd_brightness_init(void) {
void kbd_brightness_inc(void) {
if (pwmval < 9) pwmval += 2;
OCR0A = pwmval;
OCR0A = pwmval;
}
void kbd_brightness_dec(void) {
if (pwmval > 1) pwmval -= 2;
OCR0A = pwmval;
OCR0A = pwmval;
}
void kbd_brightness_set(uint8_t brite) {
pwmval = brite;
if (pwmval >= 10) pwmval = 10;
OCR0A = pwmval;
OCR0A = pwmval;
}
static void local_test(void) {
......@@ -149,42 +145,29 @@ static void local_test(void) {
}
#ifdef KBD_VARIANT_STANDALONE
#define MENU_NUM_ITEMS 4
const MenuItem menu_items[] = {
{ "Exit Menu ESC", KEY_ESCAPE },
{ "Key Backlight- F1", KEY_F1 },
{ "Key Backlight+ F2", KEY_F2 },
{ "System Status s", KEY_S }
const menu_item_t circle_menu[] = {
{ "Exit Menu", "ESC", KEY_ESCAPE, true, NULL },
{ "Key Light -", "F1", KEY_F1, false, ux_decrease_oled_brightness },
{ "Key Light +", "F2", KEY_F2, false, ux_increase_oled_brightness },
{ "System Status", "S", KEY_S, true, ux_show_status },
{ "", "", KEY_Z, true, local_test },
MENU_END
};
#else
#define MENU_NUM_ITEMS 10
const MenuItem menu_items[] = {
{ "Exit Menu ESC", KEY_ESCAPE },
{ "Power On 1", KEY_1 },
{ "Power Off 0", KEY_0 },
{ "Reset r", KEY_R },
{ "Battery Status b", KEY_B },
{ "Key Backlight- F1", KEY_F1 },
{ "Key Backlight+ F2", KEY_F2 },
{ "Wake SPC", KEY_SPACE },
{ "System Status s", KEY_S },
{ "KBD Power-Off p", KEY_P }
};
const menu_item_t circle_menu[] = {
{ "Exit Menu", "ESC", KEY_ESCAPE, true, NULL },
{ "Power On", "1", KEY_1, true, controller_turn_on_som },
{ "Power Off", "0", KEY_0, true, controller_turn_off_som },
{ "Reset", "R", KEY_R, true, NULL },
{ "Reset", "R", KEY_R, true, controller_reset_som },
{ "Battery Status", "B", KEY_B, true, ux_show_battery },
{ "Key Light -", "F1", KEY_F1, false, ux_decrease_oled_brightness },
{ "Key Light +", "F2", KEY_F2, false, ux_increase_oled_brightness },
{ "Wake", "SPC", KEY_SPACE, true, NULL },
{ "Menu Bright \x1f", "F1", KEY_F1, false, ux_decrease_oled_brightness },
{ "Menu Bright \x1e", "F2", KEY_F2, false, ux_increase_oled_brightness },
{ "Key Lights \x1f", "F3", KEY_F3, false, kbd_brightness_dec },
{ "Key Lights \x1e", "F4", KEY_F4, false, kbd_brightness_inc },
{ "Wake", "SPC", KEY_SPACE, true, controller_wake_som },
{ "System Status", "S", KEY_S, true, ux_show_status },
{ "Keyboard off", "P", KEY_P, true, controller_keyboard_off },
{ "", "", KEY_Z, true, local_test },
MENU_END
};
#endif
......@@ -272,7 +255,7 @@ static uint8_t scan_keyboard_raw(uint8_t keys[]) {
// do a tight loop of scanning, to allow the debounce logic to settle.
static uint8_t scan_keyboard(uint8_t keys[]) {
uint8_t count = 0;
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 8; i++) {
count = scan_keyboard_raw(keys);
}
return count;
......@@ -313,10 +296,10 @@ static uint8_t scan_keyboard_enhanced(uint8_t keys[]) {
void process_alerts(void) {
static int blink = 0;
if (low_battery_alert) {
ux_blink_low_battery(blink);
}
blink = 1-blink;
if (low_battery_alert) {
ux_blink_low_battery(blink);
}
blink = 1-blink;
}
int main(void) {
......@@ -352,6 +335,11 @@ int main(void) {
Delay_MS(10);
}
// FIXME testing
// 16MHz clock (1)
// TCCR1B = (1);
int counter = 0;
while (true) {
// do our own (non-usb) scan, too, so we can handle the circle menu
......@@ -413,63 +401,6 @@ void SetupHardware()
USB_Init();
}
/* Setup the AVR to enter the Power-Down state to greatly save power.
* Configures all outputs to be in the low state if possible, and disables
* services like USB and Serial.
*
* Will leave the ports setup so that the Circle key row is being scanned
* so when the watchdog wakes up it can quickly check and go back to sleep if not
* Added by Chartreuse - 2021/08/14
*
*/
void EnterPowerOff(void)
{
USB_Disable(); // Stop USB stack so it doesn't wake us up
kbd_brightness_set(0);
// Turn off OLED to save power
gfx_clear_screen();
gfx_off();
// Disable ADC to save even more power
ADCSRA=0;
cli(); // No interrupts
// Set all ports not floating if possible, leaving pullups alone
PORTB=0x3F; // Leave pull-up on all the columns on PB0-3, drive rows 2-3 high, 1-low
PORTC=0xC0;
PORTD=0xF0; // Keep pullup on PD5 like setup did, drive rows 4,5,6 high
PORTE=0x40; // Pullup on PE6
PORTF=0xFF; // Pullups on PF (columns)
// ROW1 is the only row driven low and left low, thus is always ready to be read out
// We just need to check COL14 (PC6) if it is low (pressed) or high
// Unfortunatly the circle key is on COL14(PC6) which doesn't have pin change interrupt
// capabilities, so we need to wake up every so often to check if it is pressed, and
// if so bring us out of power-off
// We can use the Watchdog timer to do this.
do {
wdt_reset();
WDTCSR = (1<<WDCE) | (1<<WDE); // Enable writes to watchdog
WDTCSR = (1<<WDIE) | (1<<WDE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0); // Interrupt mode, 1s timeout
// Enter Power-save mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei(); // Enable interrupts so we can actually wake
sleep_cpu(); // Actually go to sleep
// Zzzzzz
sleep_disable(); // We've woken up
sei();
// Check if circle key has been pressed (active-low)
// If not reset the watchdog and try again
} while(PINC&(1<<6));
// Resume and reinitialize hardware
SetupHardware();
}
ISR(WDT_vect)
{
// WDT interrupt enable and flag cleared on entry
......
......@@ -85,5 +85,3 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
const uint8_t ReportType,
const void* ReportData,
const uint16_t ReportSize);
void EnterPowerOff(void);
......@@ -140,6 +140,62 @@ void controller_wake_som(void) {
flush();
}
/*
* Setup the AVR to enter the Power-Down state to greatly save power.
* Configures all outputs to be in the low state if possible, and disables
* services like USB and Serial.
*
* Will leave the ports setup so that the Circle key row is being scanned
* so when the watchdog wakes up it can quickly check and go back to sleep if not
* Added by Chartreuse - 2021/08/14
*/
void controller_turn_off_keyboard(void) {
USB_Disable(); // Stop USB stack so it doesn't wake us up
kbd_brightness_set(0);
// Turn off OLED to save power
gfx_clear_screen();
gfx_off();
// Disable ADC to save even more power
ADCSRA = 0;
cli(); // No interrupts
// Set all ports not floating if possible, leaving pullups alone
PORTB = 0x3F; // Leave pull-up on all the columns on PB0-3, drive rows 2-3 high, 1-low
PORTC = 0xC0;
PORTD = 0xF0; // Keep pullup on PD5 like setup did, drive rows 4,5,6 high
PORTE = 0x40; // Pullup on PE6
PORTF = 0xFF; // Pullups on PF (columns)
// ROW1 is the only row driven low and left low, thus is always ready to be read out
// We just need to check COL14 (PC6) if it is low (pressed) or high
// Unfortunatly the circle key is on COL14(PC6) which doesn't have pin change interrupt
// capabilities, so we need to wake up every so often to check if it is pressed, and
// if so bring us out of power-off
// We can use the Watchdog timer to do this.
do {
wdt_reset();
WDTCSR = (1<<WDCE) | (1<<WDE); // Enable writes to watchdog
WDTCSR = (1<<WDIE) | (1<<WDE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0); // Interrupt mode, 1s timeout
// Enter Power-save mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei(); // Enable interrupts so we can actually wake
sleep_cpu(); // Actually go to sleep
// Zzzzzz
sleep_disable(); // We've woken up
sei();
// Check if circle key has been pressed (active-low)
// If not reset the watchdog and try again
} while (PINC & (1 << 6));
// Resume and reinitialize hardware
SetupHardware();
}
void controller_turn_off_aux(void) {
controller_send("3p");
flush();
......
......@@ -25,6 +25,7 @@ void controller_turn_on_som(void);
void controller_turn_off_som(void);
void controller_reset_som(void);
void controller_wake_som(void);
void controller_turn_off_keyboard(void);
void controller_turn_off_aux(void);
void controller_turn_on_aux(void);
void controller_enable_som_uart(void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment