mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2026-03-26 05:52:38 +01:00
add set kbd backlight via i2c example in picocalc_helloworld
This commit is contained in:
@@ -77,6 +77,34 @@ int read_battery() {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user