Skip to content

Commit

Permalink
Display error screen if keyboard not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
OtherCrashOverride committed Oct 18, 2018
1 parent e920e5a commit 373d558
Showing 7 changed files with 8,300 additions and 13 deletions.
Binary file added assets/baseline_error_outline_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/baseline_keyboard_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/image_keyboard_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion components/frodo/Display.cpp
Original file line number Diff line number Diff line change
@@ -88,6 +88,8 @@ extern "C"
#include "../odroid/odroid_input.h"
#include "../odroid/odroid_audio.h"
#include "../odroid/odroid_system.h"

#include "../../main/image_keyboard_error.h"
}


@@ -228,7 +230,18 @@ C64Display::C64Display(C64 *the_c64) : TheC64(the_c64)
if(keyboardMutex == NULL) abort();

odroid_keyboard_event_callback_set(&keyboard_callback);
odroid_keyboard_init();
if (!odroid_keyboard_init())
{
printf("ERROR: Keyboard not found.\n");

ili9341_write_frame_rectangleLE(0, 0, 320, 240, (uint16_t*)image_keyboard_error.pixel_data);

while(1)
{
// loop forever
vTaskDelay(1);
}
}

odroid_input_battery_level_init();
}
65 changes: 54 additions & 11 deletions components/odroid/odroid_keyboard.c
Original file line number Diff line number Diff line change
@@ -171,6 +171,33 @@ static void write_byte(uint8_t reg, uint8_t value)
}
}

static bool try_write_byte(uint8_t reg, uint8_t value)
{
i2c_cmd_handle_t cmd;
int ret;
uint8_t buttons;

cmd = i2c_cmd_link_create();

i2c_master_start(cmd);
i2c_master_write_byte(cmd, TCA8418_ADDR << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
i2c_master_write_byte(cmd, value, ACK_CHECK_EN);
i2c_master_stop(cmd);

ret = i2c_master_cmd_begin(KEYBOARD_I2C_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);

if (ret == ESP_OK)
{
return true;
}
else
{
return false;
}
}

static uint8_t read_byte(uint8_t reg)
{
i2c_cmd_handle_t cmd;
@@ -384,8 +411,11 @@ static void odroid_keyboard_task()
}


void odroid_keyboard_init()
bool odroid_keyboard_init()
{
bool result;


i2c_semaphore = xSemaphoreCreateBinary();
if (!i2c_semaphore) abort();

@@ -415,20 +445,33 @@ void odroid_keyboard_init()
i2c_init();


write_byte(REG_CFG, CFG_INT_CFG | CFG_KE_IEN);
write_byte(REG_INT_STAT, 0x1f); // clear all irqs
if (try_write_byte(REG_CFG, CFG_INT_CFG | CFG_KE_IEN))
{
write_byte(REG_INT_STAT, 0x1f); // clear all irqs

write_byte(REG_KP_GPIO1, 0x7f); // ROW0-7
write_byte(REG_KP_GPIO2, 0xff); // COL0-7
write_byte(REG_KP_GPIO3, 0x00); // COL8-9

write_byte(REG_KP_GPIO1, 0x7f); // ROW0-7
write_byte(REG_KP_GPIO2, 0xff); // COL0-7
write_byte(REG_KP_GPIO3, 0x00); // COL8-9
write_byte(REG_GPIO_DIR1, 0x80); // ROW0-7
write_byte(REG_GPIO_DIR3, 0x03); // COL8-9

write_byte(REG_GPIO_DIR1, 0x80); // ROW0-7
write_byte(REG_GPIO_DIR3, 0x03); // COL8-9


odroid_keyboard_initialized = true;
xTaskCreatePinnedToCore(&odroid_keyboard_task, "keyboard_task", 2048, NULL, 5, NULL, 1);

odroid_keyboard_initialized = true;
xTaskCreatePinnedToCore(&odroid_keyboard_task, "keyboard_task", 2048, NULL, 5, NULL, 1);
result = true;
}
else
{
result = false;

gpio_isr_handler_remove(KEYBOARD_INT);
gpio_uninstall_isr_service();
}

return result;
}

odroid_keyboard_led_t odroid_keyboard_leds_get()
@@ -451,4 +494,4 @@ void odroid_keyboard_leds_set(odroid_keyboard_led_t value)
write_byte(REG_GPIO_DAT_OUT1, (value & ODROID_KEYBOARD_LED_St) ? 0x80 : 0x00);

xSemaphoreGive(i2c_mutex);
}
}
3 changes: 2 additions & 1 deletion components/odroid/odroid_keyboard.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>


typedef enum {
@@ -97,7 +98,7 @@ typedef struct



void odroid_keyboard_init();
bool odroid_keyboard_init();
void odroid_keyboard_state_key_set(odroid_keyboardstate_t* state, odroid_key_t key, odroid_keystate_t value);
odroid_keystate_t odroid_keyboard_state_key_get(odroid_keyboardstate_t* state, odroid_key_t key);
odroid_keyboardstate_t odroid_keyboard_state_get();
Loading

0 comments on commit 373d558

Please sign in to comment.