updates to work with beeper

This commit is contained in:
SQFMI 2023-04-21 11:54:49 -04:00
parent f085518d78
commit 1e29efb63b
7 changed files with 137 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build
*.txt.user
__pycache__
.DS_Store

View File

@ -2,6 +2,7 @@
#include "fifo.h"
#include "keyboard.h"
#include "reg.h"
#include "pi.h"
#include <pico/stdlib.h>
@ -36,6 +37,12 @@ static const uint8_t col_pins[NUM_OF_COLS] =
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
/*
In https://github.com/wallComputer/bbqX0kbd_driver/blob/main/source/mod_src/bbq20kbd_pmod_codes.h
'f' is apped to KEY_ESC
*/
static const struct entry kbd_entries[][NUM_OF_COLS] =
{
{ { KEY_JOY_CENTER }, { 'W', '1' }, { 'G', '/' }, { 'S', '4' }, { 'L', '"' }, { 'H' , ':' } },
@ -44,7 +51,7 @@ static const struct entry kbd_entries[][NUM_OF_COLS] =
{ { }, { ' ', '\t' }, { 'C', '9' }, { 'Z', '7' }, { 'M', '.' }, { 'N', ',' } },
{ { KEY_BTN_LEFT2 }, { .mod = KEY_MOD_ID_SYM }, { 'T', '(' }, { 'D', '5' }, { 'I', '-' }, { 'Y', ')' } },
{ { KEY_BTN_RIGHT1 }, { .mod = KEY_MOD_ID_ALT }, { 'V', '?' }, { 'X', '8' }, { '$', '`' }, { 'B', '!' } },
{ { }, { 'A', '*' }, { .mod = KEY_MOD_ID_SHR }, { 'P', '@' }, { '\b' }, { '\n', '|' } },
{ { }, { 'A', '*' }, { .mod = KEY_MOD_ID_SHR }, { 'P', '@' }, { '\b', 'f' }, { '\n', '|' } },
};
#if NUM_OF_BTNS > 0
@ -77,6 +84,17 @@ static struct
bool numlock;
} self;
static int64_t rk(alarm_id_t id, void *user_data)
{
(void)id;
const int data = (int)user_data;
keyboard_inject_event((char)data, KEY_STATE_RELEASED);
return 0;
}
static void transition_to(struct list_item * const p_item, const enum key_state next_state)
{
const struct entry * const p_entry = p_item->p_entry;
@ -193,9 +211,24 @@ static void next_item_state(struct list_item * const p_item, const bool pressed)
break;
case KEY_STATE_HOLD:
if (!pressed) {
transition_to(p_item, KEY_STATE_RELEASED);
} else if ((to_ms_since_boot(get_absolute_time()) - p_item->hold_start_time) > LONG_HOLD_MS) {
if(p_item->effective_key == KEY_BTN_RIGHT2){
//inject power key
char key = KEY_POWER;
keyboard_inject_event(key, KEY_STATE_PRESSED);
//delay release key
add_alarm_in_ms(10, rk, (void*)(int)key, true);
}
transition_to(p_item, KEY_STATE_LONG_HOLD);
}
break;
case KEY_STATE_LONG_HOLD:
if (!pressed)
transition_to(p_item, KEY_STATE_RELEASED);
break;
break;
case KEY_STATE_RELEASED:
{
@ -325,7 +358,7 @@ bool keyboard_is_key_down(char key)
if (item->p_entry == NULL)
continue;
if ((item->state != KEY_STATE_PRESSED) && (item->state != KEY_STATE_HOLD))
if ((item->state != KEY_STATE_PRESSED) && (item->state != KEY_STATE_HOLD) && (item->state != KEY_STATE_LONG_HOLD))
continue;
if (item->effective_key != key)

View File

@ -9,6 +9,7 @@ enum key_state
KEY_STATE_PRESSED,
KEY_STATE_HOLD,
KEY_STATE_RELEASED,
KEY_STATE_LONG_HOLD,
};
enum key_mod
@ -41,6 +42,9 @@ enum key_mod
#define KEY_MOD_SHR 0x1C // Right Shift
#define KEY_MOD_SYM 0x1D
#define KEY_POWER 0xEE
#define LONG_HOLD_MS 3000
struct key_callback
{
void (*func)(char, enum key_state);

View File

@ -11,6 +11,7 @@
#include "reg.h"
#include "touchpad.h"
#include "usb.h"
#include "pi.h"
// since the SDK doesn't support per-GPIO irq, we use this global irq and forward it
static void gpio_irq(uint gpio, uint32_t events)
@ -47,6 +48,8 @@ int main(void)
// For now, the `gpio` param is ignored and all enabled GPIOs generate the irq
gpio_set_irq_enabled_with_callback(0xFF, 0, true, &gpio_irq);
pi_init(); //turns on the pi
#ifndef NDEBUG
printf("Starting main loop\r\n");
#endif

28
app/pi.c Normal file
View File

@ -0,0 +1,28 @@
#include "pi.h"
#include "reg.h"
#include "keyboard.h"
#include "gpioexp.h"
#include "backlight.h"
#include <pico/stdlib.h>
void pi_init(void)
{
//Status LED
gpio_init(PIN_LED_R);
gpio_set_dir(PIN_LED_R, GPIO_OUT);
gpio_put(PIN_LED_R, 1);
gpio_init(PIN_LED_G);
gpio_set_dir(PIN_LED_G, GPIO_OUT);
gpio_put(PIN_LED_G, 1);
gpio_init(PIN_LED_B);
gpio_set_dir(PIN_LED_B, GPIO_OUT);
gpio_put(PIN_LED_B, 1);
//Pi Power On
gpio_init(PIN_PI_PWR);
gpio_set_dir(PIN_PI_PWR, GPIO_OUT);
gpio_put(PIN_PI_PWR, 1);
}

5
app/pi.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stdint.h>
void pi_init(void);

60
boards/beeper.h Normal file
View File

@ -0,0 +1,60 @@
#pragma once
#define USB_VID 0x1209
#define USB_PID 0xB182
#define USB_PRODUCT "BBQ20KBD"
#define PIN_INT 0
#define PIN_BKL 25
#define PIN_SDA 18
#define PIN_SCL 23
#define PIN_TP_RESET 16
#define PIN_TP_MOTION 22
#define PIN_TP_SHUTDOWN 24
#define PIN_PUPPET_SDA 28
#define PIN_PUPPET_SCL 29
/** beeper specific pins **/
#define PIN_PI_PWR 15
#define PIN_PI_SHUTDOWN 21
#define PIN_LED_R 20
#define PIN_LED_G 19
#define PIN_LED_B 17
#define PIN_BAT_ADC 26
#define NUM_OF_ROWS 7
#define PINS_ROWS \
14, \
13, \
12, \
11, \
10, \
9, \
8
#define NUM_OF_COLS 6
#define PINS_COLS \
1, \
2, \
3, \
7, \
6, \
5
#define NUM_OF_BTNS 1
#define PINS_BTNS \
4,
#define BTN_KEYS \
{ KEY_BTN_RIGHT2 },
#define PIN_GPIOEXP0 PIN_PI_SHUTDOWN
// #define PIN_GPIOEXP1 17
// #define PIN_GPIOEXP2 19
// #define PIN_GPIOEXP3 21
// #define PIN_GPIOEXP4 26
// #define PICO_DEFAULT_UART 1
// #define PICO_DEFAULT_UART_TX_PIN 20