Skip to content

Commit

Permalink
implement reading MENU/OSD/USER buttons from GPIO
Browse files Browse the repository at this point in the history
  • Loading branch information
hansfbaier committed Feb 12, 2024
1 parent b2ac161 commit 5bc5c72
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
57 changes: 37 additions & 20 deletions fpga_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,39 @@ static const char *spi_device = "/dev/spidev1.0";

#ifdef RASPBERRY_PI
#define SPI_SPEED 8000000
#define GPIIO_PIN_FPGA_RESET 22
#define GPIIO_PIN_FPGA_EN 23
#define GPIIO_PIN_OSD_EN 24
#define GPIIO_PIN_IO_EN 25
#define GPIO_PIN_FPGA_RESET 22
#define GPIO_PIN_FPGA_EN 23
#define GPIO_PIN_OSD_EN 24
#define GPIO_PIN_IO_EN 25
#endif

#ifdef ORANGEPI_ZERO_2W
#define SPI_SPEED 30000000
#define GPIIO_PIN_FPGA_RESET 261
#define GPIIO_PIN_FPGA_EN 270
#define GPIIO_PIN_OSD_EN 228
#define GPIIO_PIN_IO_EN 262
#define GPIO_PIN_FPGA_RESET 261
#define GPIO_PIN_FPGA_EN 270
#define GPIO_PIN_OSD_EN 228
#define GPIO_PIN_IO_EN 262
#define GPIO_PIN_BTN_MENU 268
#define GPIO_PIN_BTN_OSD 258
#define GPIO_PIN_BTN_USER 272
#endif

#ifdef SIPEED_LICHEE_RV
#define SPI_SPEED 8000000
#define GPIIO_PIN_FPGA_RESET 102
#define GPIIO_PIN_FPGA_EN 103
#define GPIIO_PIN_OSD_EN 104
#define GPIIO_PIN_IO_EN 105
#define GPIO_PIN_FPGA_RESET 102
#define GPIO_PIN_FPGA_EN 103
#define GPIO_PIN_OSD_EN 104
#define GPIO_PIN_IO_EN 105
#endif

static struct gpiod_chip *gpio_chip;
static struct gpiod_line *gpio_line_fpga_reset;
static struct gpiod_line *gpio_line_fpga_en;
static struct gpiod_line *gpio_line_osd_en;
static struct gpiod_line *gpio_line_io_en;
static struct gpiod_line *gpio_line_btn_menu;
static struct gpiod_line *gpio_line_btn_osd;
static struct gpiod_line *gpio_line_btn_user;

const static bool spi_trace = 0;
const static bool spi_en_trace = 0;
Expand Down Expand Up @@ -138,20 +144,29 @@ int fpga_io_init()
gpio_chip = gpiod_chip_open_by_name(gpio_chip_name);
if (!gpio_chip) goto err;

gpio_line_fpga_reset = gpiod_chip_get_line(gpio_chip, GPIIO_PIN_FPGA_RESET);
gpio_line_fpga_en = gpiod_chip_get_line(gpio_chip, GPIIO_PIN_FPGA_EN);
gpio_line_osd_en = gpiod_chip_get_line(gpio_chip, GPIIO_PIN_OSD_EN);
gpio_line_io_en = gpiod_chip_get_line(gpio_chip, GPIIO_PIN_IO_EN);
gpio_line_fpga_reset = gpiod_chip_get_line(gpio_chip, GPIO_PIN_FPGA_RESET);
gpio_line_fpga_en = gpiod_chip_get_line(gpio_chip, GPIO_PIN_FPGA_EN);
gpio_line_osd_en = gpiod_chip_get_line(gpio_chip, GPIO_PIN_OSD_EN);
gpio_line_io_en = gpiod_chip_get_line(gpio_chip, GPIO_PIN_IO_EN);
gpio_line_btn_menu = gpiod_chip_get_line(gpio_chip, GPIO_PIN_BTN_MENU);
gpio_line_btn_osd = gpiod_chip_get_line(gpio_chip, GPIO_PIN_BTN_OSD);
gpio_line_btn_user = gpiod_chip_get_line(gpio_chip, GPIO_PIN_BTN_USER);

if (!gpio_line_fpga_en ||
!gpio_line_osd_en ||
!gpio_line_io_en ||
!gpio_line_fpga_reset) goto err;
!gpio_line_fpga_reset ||
!gpio_line_btn_menu ||
!gpio_line_btn_osd ||
!gpio_line_btn_user ) goto err;

gpiod_line_request_output(gpio_line_fpga_reset, "FPGA_RESET", 0);
gpiod_line_request_output(gpio_line_fpga_en, "FPGA_EN", 0);
gpiod_line_request_output(gpio_line_osd_en, "OSD_EN", 0);
gpiod_line_request_output(gpio_line_io_en, "IO_EN", 0);

gpiod_line_request_input(gpio_line_btn_menu, "BTN_MENU");
gpiod_line_request_input(gpio_line_btn_osd, "BTN_OSD");
gpiod_line_request_input(gpio_line_btn_user, "BTN_USER");
return 0;

err:
Expand Down Expand Up @@ -182,8 +197,10 @@ void fpga_set_led(uint32_t on)

int fpga_get_buttons()
{
// OSD/User Buttons
return 0;
int btn_osd = !gpiod_line_get_value(gpio_line_btn_osd);
int btn_user = !gpiod_line_get_value(gpio_line_btn_user);
int btn_menu = !gpiod_line_get_value(gpio_line_btn_menu);
return btn_osd | (btn_user << 1) | (btn_menu << 2);
}

int fpga_get_io_type()
Expand Down
2 changes: 1 addition & 1 deletion menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static uint32_t menu_key_get(void)
{
static unsigned long longpress = 0, longpress_consumed = 0;
static unsigned char last_but = 0;
unsigned char but = user_io_menu_button();
unsigned char but = user_io_osd_button();

if (but && !last_but) longpress = GetTimer(3000);
if (but && CheckTimer(longpress) && !longpress_consumed)
Expand Down
4 changes: 2 additions & 2 deletions user_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ char *user_io_get_confstr(int index)
}

static char cur_btn = 0;
char user_io_menu_button()
char user_io_osd_button()
{
return (cur_btn & BUTTON_OSD) ? 1 : 0;
}
Expand Down Expand Up @@ -2693,7 +2693,7 @@ void user_io_send_buttons(char force)

cur_btn = fpga_get_buttons();

if (user_io_menu_button()) map |= BUTTON1;
if (user_io_osd_button()) map |= BUTTON1;
if (user_io_user_button()) map |= BUTTON2;
if (kbd_reset || kbd_reset_ovr) map |= BUTTON2;

Expand Down
2 changes: 1 addition & 1 deletion user_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void user_io_init(const char *path, const char *xml);
unsigned char user_io_core_type();
void user_io_read_core_name();
void user_io_poll();
char user_io_menu_button();
char user_io_osd_button();
char user_io_user_button();
void user_io_osd_key_enable(char);
int user_io_get_kbd_reset();
Expand Down

0 comments on commit 5bc5c72

Please sign in to comment.