mirror of
https://github.com/whowechina/chu_pico.git
synced 2025-02-21 04:16:28 +01:00
Overclock for best latency (still stable)
This commit is contained in:
parent
0482e01fbe
commit
8f833808ed
Binary file not shown.
@ -27,19 +27,19 @@ const int pitch = 160;
|
||||
|
||||
void air_init()
|
||||
{
|
||||
i2c_init(TOF_I2C, 400 * 1000);
|
||||
gpio_set_function(TOF_SDA, GPIO_FUNC_I2C);
|
||||
gpio_set_function(TOF_SCL, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(TOF_SDA);
|
||||
gpio_pull_up(TOF_SCL);
|
||||
i2c_init(I2C_PORT, I2C_FREQ);
|
||||
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
|
||||
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(I2C_SDA);
|
||||
gpio_pull_up(I2C_SCL);
|
||||
|
||||
i2c_hub_init();
|
||||
|
||||
for (int i = 0; i < sizeof(TOF_LIST); i++) {
|
||||
i2c_select(TOF_I2C, 1 << TOF_LIST[i]);
|
||||
gp2y0e_write(TOF_I2C, 0xa8, 0); // Accumulation 0:1, 1:5, 2:30, 3:10
|
||||
gp2y0e_write(TOF_I2C, 0x3f, 0x30); // Filter 0x00:7, 0x10:5, 0x20:9, 0x30:1
|
||||
gp2y0e_write(TOF_I2C, 0x13, 5); // Pulse [3..7]:[40, 80, 160, 240, 320] us
|
||||
i2c_select(I2C_PORT, 1 << TOF_LIST[i]);
|
||||
gp2y0e_write(I2C_PORT, 0xa8, 0); // Accumulation 0:1, 1:5, 2:30, 3:10
|
||||
gp2y0e_write(I2C_PORT, 0x3f, 0x30); // Filter 0x00:7, 0x10:5, 0x20:9, 0x30:1
|
||||
gp2y0e_write(I2C_PORT, 0x13, 5); // Pulse [3..7]:[40, 80, 160, 240, 320] us
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,8 +92,8 @@ unsigned air_value(uint8_t index)
|
||||
void air_update()
|
||||
{
|
||||
for (int i = 0; i < sizeof(TOF_LIST); i++) {
|
||||
i2c_select(TOF_I2C, 1 << TOF_LIST[i]);
|
||||
distances[i] = gp2y0e_dist16(TOF_I2C);
|
||||
i2c_select(I2C_PORT, 1 << TOF_LIST[i]);
|
||||
distances[i] = gp2y0e_dist16(I2C_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,12 @@
|
||||
|
||||
#if defined BOARD_CHU_PICO
|
||||
|
||||
#define MPR121_I2C i2c0
|
||||
#define MPR121_SDA 16
|
||||
#define MPR121_SCL 17
|
||||
#define I2C_PORT i2c0
|
||||
#define I2C_SDA 16
|
||||
#define I2C_SCL 17
|
||||
#define I2C_FREQ 733*1000
|
||||
|
||||
// if TOF_I2C is same as MPR121_I2C, TOF_SCL and TOF_SDA will be ignored
|
||||
#define TOF_I2C i2c0
|
||||
#define TOF_SDA 16
|
||||
#define TOF_SCL 17
|
||||
#define TOF_I2C_HUB 19
|
||||
#define I2C_HUB_EN 19
|
||||
|
||||
#define TOF_MUX_LIST { 1, 2, 0, 4, 5 }
|
||||
|
||||
|
@ -13,10 +13,10 @@
|
||||
#define I2C_HUB_ADDR 0x70
|
||||
static inline void i2c_hub_init()
|
||||
{
|
||||
// pull up gpio TOF_I2C_HUB
|
||||
gpio_init(TOF_I2C_HUB);
|
||||
gpio_set_dir(TOF_I2C_HUB, GPIO_OUT);
|
||||
gpio_put(TOF_I2C_HUB, 1);
|
||||
// pull up gpio I2C_HUB_EN
|
||||
gpio_init(I2C_HUB_EN);
|
||||
gpio_set_dir(I2C_HUB_EN, GPIO_OUT);
|
||||
gpio_put(I2C_HUB_EN, 1);
|
||||
}
|
||||
|
||||
static inline void i2c_select(i2c_inst_t *i2c_port, uint8_t chn)
|
||||
|
@ -177,8 +177,12 @@ static void run_lights()
|
||||
static void core1_loop()
|
||||
{
|
||||
while (1) {
|
||||
run_lights();
|
||||
rgb_update();
|
||||
|
||||
slider_update_baseline();
|
||||
fps_count(1);
|
||||
print_fps();
|
||||
sleep_ms(1);
|
||||
}
|
||||
}
|
||||
@ -186,11 +190,7 @@ static void core1_loop()
|
||||
static void core0_loop()
|
||||
{
|
||||
while(1) {
|
||||
run_lights();
|
||||
fps_count(0);
|
||||
print_fps();
|
||||
|
||||
slider_update_baseline();
|
||||
|
||||
slider_update();
|
||||
air_update();
|
||||
@ -204,8 +204,8 @@ static void core0_loop()
|
||||
|
||||
void init()
|
||||
{
|
||||
sleep_ms(200);
|
||||
// set_sys_clock_khz(166000, true);
|
||||
sleep_ms(100);
|
||||
set_sys_clock_khz(150000, true);
|
||||
board_init();
|
||||
tusb_init();
|
||||
stdio_init_all();
|
||||
|
@ -36,8 +36,8 @@ static struct mpr121_sensor mpr121[3];
|
||||
|
||||
static void mpr121_read_many(uint8_t addr, uint8_t reg, uint8_t *buf, size_t n)
|
||||
{
|
||||
i2c_write_blocking_until(MPR121_I2C, addr, ®, 1, true, time_us_64() + 2000);
|
||||
i2c_read_blocking_until(MPR121_I2C, addr, buf, n, false, time_us_64() + 2000);
|
||||
i2c_write_blocking_until(I2C_PORT, addr, ®, 1, true, time_us_64() + 2000);
|
||||
i2c_read_blocking_until(I2C_PORT, addr, buf, n, false, time_us_64() + 2000);
|
||||
}
|
||||
|
||||
static void mpr121_read_many16(uint8_t addr, uint8_t reg, uint16_t *buf, size_t n)
|
||||
@ -63,14 +63,14 @@ static void init_baseline()
|
||||
|
||||
void slider_init()
|
||||
{
|
||||
i2c_init(MPR121_I2C, 400 * 1000);
|
||||
gpio_set_function(MPR121_SDA, GPIO_FUNC_I2C);
|
||||
gpio_set_function(MPR121_SCL, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(MPR121_SDA);
|
||||
gpio_pull_up(MPR121_SCL);
|
||||
i2c_init(I2C_PORT, I2C_FREQ);
|
||||
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
|
||||
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(I2C_SDA);
|
||||
gpio_pull_up(I2C_SCL);
|
||||
|
||||
for (int m = 0; m < 3; m++) {
|
||||
mpr121_init(MPR121_I2C, MPR121_ADDR + m, mpr121 + m);
|
||||
mpr121_init(I2C_PORT, MPR121_ADDR + m, mpr121 + m);
|
||||
}
|
||||
|
||||
init_baseline();
|
||||
@ -82,9 +82,9 @@ void slider_update()
|
||||
mpr121_read_many16(MPR121_ADDR, reg, readout, 12);
|
||||
mpr121_read_many16(MPR121_ADDR + 1, reg, readout + 12, 12);
|
||||
mpr121_read_many16(MPR121_ADDR + 2, reg, readout + 24, 12);
|
||||
mpr121_touched(touch, mpr121);
|
||||
mpr121_touched(touch + 1, mpr121 + 1);
|
||||
mpr121_touched(touch + 2, mpr121 + 2);
|
||||
// mpr121_touched(touch, mpr121);
|
||||
// mpr121_touched(touch + 1, mpr121 + 1);
|
||||
// mpr121_touched(touch + 2, mpr121 + 2);
|
||||
}
|
||||
|
||||
void slider_update_baseline()
|
||||
|
Loading…
x
Reference in New Issue
Block a user