add pico_multi_booter code

This commit is contained in:
cuu
2025-05-19 14:50:19 +08:00
parent f0058240cd
commit beb05b7ca7
134 changed files with 164897 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
#ifndef CONF_APP_H
#define CONF_APP_H
#define SLAVE_ADDRESS 0x1F
#define FIFO_SIZE 31
#define INT_DURATION_MS 1
#ifndef CONFIG_PMU_SDA
#define CONFIG_PMU_SDA PB11
#endif
#ifndef CONFIG_PMU_SCL
#define CONFIG_PMU_SCL PB10
#endif
#ifndef CONFIG_PMU_IRQ
#define CONFIG_PMU_IRQ PC9
#endif
#define LOW_BAT_VAL 20
#define LCD_BACKLIGHT_STEP 10
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1 << (bit)))
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit) ))
#endif

View File

@@ -0,0 +1,112 @@
#include <stdio.h>
#include <pico/stdio.h>
#include "i2ckbd.h"
static uint8_t i2c_inited = 0;
void init_i2c_kbd() {
//gpio_set_function(I2C_KBD_SCL, GPIO_FUNC_I2C);
//gpio_set_function(I2C_KBD_SDA, GPIO_FUNC_I2C);
//i2c_init(I2C_KBD_MOD, I2C_KBD_SPEED);
//gpio_pull_up(I2C_KBD_SCL);
//gpio_pull_up(I2C_KBD_SDA);
i2c_inited = 1;
}
int read_i2c_kbd() {
int retval;
static int ctrlheld = 0;
uint16_t buff = 0;
unsigned char msg[2];
int c = -1;
msg[0] = 0x09;
if (i2c_inited == 0) return -1;
retval = i2c_write_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, msg, 1, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_i2c_kbd i2c write error\n");
return -1;
}
sleep_ms(16);
retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) &buff, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_i2c_kbd i2c read error read\n");
return -1;
}
if (buff != 0) {
if (buff == 0x7e03)ctrlheld = 0;
else if (buff == 0x7e02) {
ctrlheld = 1;
} else if ((buff & 0xff) == 1) {//pressed
c = buff >> 8;
int realc = -1;
switch (c) {
default:
realc = c;
break;
}
c = realc;
if (c >= 'a' && c <= 'z' && ctrlheld)c = c - 'a' + 1;
}
return c;
}
return -1;
}
int read_battery() {
int retval;
uint16_t buff = 0;
unsigned char msg[2];
msg[0] = 0x0b;
if (i2c_inited == 0) return -1;
retval = i2c_write_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, msg, 1, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_battery i2c write error\n");
return -1;
}
sleep_ms(16);
retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) &buff, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_battery i2c read error read\n");
return -1;
}
if (buff != 0) {
return buff;
}
return -1;
}
int set_kbd_backlight(uint8_t val){
int retval;
uint16_t buff = 0;
unsigned char msg[2];
msg[0] = 0x0A;
msg[1] = val;
bitSet(msg[0],7);
if (i2c_inited == 0) return -1;
retval = i2c_write_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, msg, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_battery i2c write error\n");
return -1;
}
sleep_ms(16);
retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) &buff, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
printf("read_battery i2c read error read\n");
return -1;
}
if (buff != 0) {
return buff;
}
return -1;
}

View File

@@ -0,0 +1,25 @@
#ifndef I2C_KEYBOARD_H
#define I2C_KEYBOARD_H
#include <pico/stdlib.h>
#include <pico/platform.h>
#include <hardware/gpio.h>
#include <hardware/i2c.h>
#define I2C_KBD_MOD i2c1
#define I2C_KBD_SDA 6
#define I2C_KBD_SCL 7
#define I2C_KBD_SPEED 10000 // if dual i2c, then the speed of keyboard i2c should be 10khz
#define I2C_KBD_ADDR 0x1F
void init_i2c_kbd();
int read_i2c_kbd();
int read_battery();
int set_kbd_backlight(uint8_t);
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
#define bitSet(value, bit) ((value) |= (1 << (bit)))
#endif