mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2025-12-12 10:18:54 +01:00
add set kbd backlight via i2c example in picocalc_helloworld
This commit is contained in:
parent
f2fa13099c
commit
111319e22d
@ -77,6 +77,34 @@ int read_battery() {
|
|||||||
return -1;
|
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) {
|
if (buff != 0) {
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,10 @@
|
|||||||
void init_i2c_kbd();
|
void init_i2c_kbd();
|
||||||
int read_i2c_kbd();
|
int read_i2c_kbd();
|
||||||
int read_battery();
|
int read_battery();
|
||||||
|
int set_kbd_backlight(uint8_t);
|
||||||
|
|
||||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
|
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
|
||||||
|
#define bitSet(value, bit) ((value) |= (1 << (bit)))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -220,6 +220,16 @@ void test_battery(){
|
|||||||
lcd_print_string(buf);
|
lcd_print_string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_kbd_backlight(uint8_t val) {
|
||||||
|
char buf[64];
|
||||||
|
int kbd_backlight = set_kbd_backlight(val);
|
||||||
|
kbd_backlight = kbd_backlight>>8;
|
||||||
|
|
||||||
|
sprintf(buf, "kbd backlight %d\n", kbd_backlight);
|
||||||
|
printf("%s", buf);
|
||||||
|
lcd_print_string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
set_sys_clock_khz(133000, true);
|
set_sys_clock_khz(133000, true);
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
@ -252,6 +262,13 @@ int main() {
|
|||||||
|
|
||||||
sleep_ms(2000);
|
sleep_ms(2000);
|
||||||
test_battery();
|
test_battery();
|
||||||
|
test_kbd_backlight(50);
|
||||||
|
sleep_ms(1000);
|
||||||
|
test_kbd_backlight(100);
|
||||||
|
sleep_ms(1000);
|
||||||
|
test_kbd_backlight(255);
|
||||||
|
sleep_ms(1000);
|
||||||
|
test_kbd_backlight(0);
|
||||||
while (1) {
|
while (1) {
|
||||||
int c = lcd_getc(0);
|
int c = lcd_getc(0);
|
||||||
if(c != -1 && c > 0) {
|
if(c != -1 && c > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user