Read button state from display driver

dv_stick
Mike Bell 2023-05-18 18:35:52 +01:00 zatwierdzone przez Phil Howard
rodzic e295e69c72
commit 1d8c836635
4 zmienionych plików z 412 dodań i 379 usunięć

Wyświetl plik

@ -52,6 +52,14 @@ namespace pimoroni {
gpio_put(RAM_SEL, bank);
}
uint8_t DVDisplay::get_driver_gpio() {
return i2c.reg_read_uint8(I2C_ADDR, I2C_REG_GPIO);
}
uint8_t DVDisplay::get_driver_gpio_hi() {
return i2c.reg_read_uint8(I2C_ADDR, I2C_REG_GPIO_HI);
}
void DVDisplay::write(uint32_t address, size_t len, const uint16_t colour)
{
uint32_t val = colour | ((uint32_t)colour << 16);

Wyświetl plik

@ -37,6 +37,8 @@ namespace pimoroni {
// I2C
static constexpr uint I2C_ADDR = 0x0D;
static constexpr uint I2C_REG_START = 0xF9;
static constexpr uint I2C_REG_GPIO = 0xC0;
static constexpr uint I2C_REG_GPIO_HI = 0xC8;
static constexpr uint32_t base_address = 0x10000;
uint16_t width = 0;
@ -91,6 +93,12 @@ namespace pimoroni {
void init();
void flip();
uint8_t get_driver_gpio();
uint8_t get_driver_gpio_hi();
bool is_button_b_pressed() { return (get_driver_gpio() & 0x1) != 0x1; }
bool is_button_c_pressed() { return (get_driver_gpio() & 0x2) != 0x2; }
private:
static constexpr int PIXEL_BUFFER_LEN_IN_WORDS = 16;
uint32_t pixel_buffer[PIXEL_BUFFER_LEN_IN_WORDS];

Wyświetl plik

@ -56,6 +56,7 @@ int main() {
display.flip();
printf("Starting\n");
graphics.set_font("bitmap8");
constexpr int NUM_CIRCLES = 50;
struct Circle {
@ -86,12 +87,14 @@ int main() {
}
}
#if 0
for (uint i = 0; i < 128; i++) {
for (uint j = 0; j < 256; j++) {
graphics.set_pen((j << 7) | i);
graphics.pixel(Point(i, j+128));
}
}
#endif
for(int i =0 ; i < NUM_CIRCLES ; i++)
{
@ -124,6 +127,14 @@ int main() {
uint32_t render_time = time_us_32() - render_start_time;
char buffer[8];
sprintf(buffer, "%s %s %s",
gpio_get(BUTTON_A) == 0 ? "A" : " ",
display.is_button_b_pressed() ? "B" : " ",
display.is_button_c_pressed() ? "C" : " ");
graphics.set_pen(0);
graphics.text(buffer, {500,10}, FRAME_WIDTH - 500, 3);
uint32_t flip_start_time = time_us_32();
display.flip();
uint32_t flip_time = time_us_32() - flip_start_time;