1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-28 09:28:13 +00:00

fixup! feat(core): add hardware support for T3W1

This commit is contained in:
tychovrahe 2023-06-09 23:20:24 +02:00
parent f6d8bdccd2
commit 46da3b45a4
5 changed files with 88 additions and 20 deletions

View File

@ -5,6 +5,7 @@ use core::convert::TryInto;
pub enum PhysicalButton {
Left,
Right,
Power,
}
#[derive(Copy, Clone, PartialEq, Eq)]
@ -24,6 +25,7 @@ impl ButtonEvent {
let button = match button {
0 => PhysicalButton::Left,
1 => PhysicalButton::Right,
2 => PhysicalButton::Power,
_ => return Err(error::Error::OutOfRange),
};
let result = match event {

View File

@ -7,6 +7,7 @@
#define USE_SD_CARD 1
#define USE_I2C 1
#define USE_TOUCH 1
#define USE_BUTTON 1
#define USE_SBU 1
#define USE_RGB_COLORS 1
#define USE_DISP_I8080_16BIT_DW 1
@ -43,4 +44,15 @@
#define SD_ENABLE_PORT GPIOE
#define SD_ENABLE_PIN GPIO_PIN_1
#define GPIO_1_PORT GPIOC
#define GPIO_1_PIN GPIO_PIN_1
#define GPIO_2_PORT GPIOC
#define GPIO_2_PIN GPIO_PIN_6
#define GPIO_3_PORT GPIOC
#define GPIO_3_PIN GPIO_PIN_7
#define BTN_POWER_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE
#define BTN_POWER_PORT GPIOE
#define BTN_POWER_PIN GPIO_PIN_0
#endif //_TREZOR_T3W1_H

View File

@ -1,28 +1,54 @@
#include "stdbool.h"
#include STM32_HAL_H
#include "button.h"
#include TREZOR_BOARD
static char last_left = 0, last_right = 0;
void button_init(void) {
BTN_LEFT_CLK_ENA();
BTN_RIGHT_CLK_ENA();
static void init_btn(GPIO_TypeDef *port, uint16_t pin) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = BTN_LEFT_PIN;
HAL_GPIO_Init(BTN_LEFT_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = BTN_RIGHT_PIN;
HAL_GPIO_Init(BTN_RIGHT_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = pin;
HAL_GPIO_Init(port, &GPIO_InitStructure);
}
#ifdef BTN_LEFT_CLK_ENA
static bool last_left = 0;
bool button_state_left(void) { return last_left; }
#endif
#ifdef BTN_RIGHT_CLK_ENA
static bool last_right = 0;
bool button_state_right(void) { return last_right; }
#endif
#ifdef BTN_POWER_CLK_ENA
static bool last_power = 0;
bool button_state_power(void) { return last_power; }
#endif
void button_init(void) {
#ifdef BTN_LEFT_CLK_ENA
BTN_LEFT_CLK_ENA();
init_btn(BTN_LEFT_PORT, BTN_LEFT_PIN);
#endif
#ifdef BTN_RIGHT_CLK_ENA
BTN_RIGHT_CLK_ENA();
init_btn(BTN_RIGHT_PORT, BTN_RIGHT_PIN);
#endif
#ifdef BTN_POWER_CLK_ENA
BTN_POWER_CLK_ENA();
init_btn(BTN_POWER_PORT, BTN_POWER_PIN);
#endif
}
uint32_t button_read(void) {
char left = (GPIO_PIN_RESET == HAL_GPIO_ReadPin(BTN_LEFT_PORT, BTN_LEFT_PIN));
char right =
(GPIO_PIN_RESET == HAL_GPIO_ReadPin(BTN_RIGHT_PORT, BTN_RIGHT_PIN));
#ifdef BTN_LEFT_CLK_ENA
bool left = (GPIO_PIN_RESET == HAL_GPIO_ReadPin(BTN_LEFT_PORT, BTN_LEFT_PIN));
if (last_left != left) {
last_left = left;
if (left) {
@ -31,6 +57,10 @@ uint32_t button_read(void) {
return BTN_EVT_UP | BTN_LEFT;
}
}
#endif
#ifdef BTN_RIGHT_CLK_ENA
bool right =
(GPIO_PIN_RESET == HAL_GPIO_ReadPin(BTN_RIGHT_PORT, BTN_RIGHT_PIN));
if (last_right != right) {
last_right = right;
if (right) {
@ -39,9 +69,19 @@ uint32_t button_read(void) {
return BTN_EVT_UP | BTN_RIGHT;
}
}
#endif
#ifdef BTN_POWER_CLK_ENA
bool power =
(GPIO_PIN_RESET == HAL_GPIO_ReadPin(BTN_POWER_PORT, BTN_POWER_PIN));
if (last_power != power) {
last_power = power;
if (power) {
return BTN_EVT_DOWN | BTN_POWER;
} else {
return BTN_EVT_UP | BTN_POWER;
}
}
#endif
return 0;
}
char button_state_left(void) { return last_left; }
char button_state_right(void) { return last_right; }

View File

@ -20,6 +20,9 @@
#ifndef TREZORHAL_BUTTON_H
#define TREZORHAL_BUTTON_H
#include TREZOR_BOARD
#include <stdbool.h>
#include <stdint.h>
#define BTN_EVT_DOWN (1U << 24)
@ -27,10 +30,19 @@
#define BTN_LEFT 0
#define BTN_RIGHT 1
#define BTN_POWER 2
void button_init(void);
uint32_t button_read(void);
char button_state_left(void);
char button_state_right(void);
#ifdef BTN_LEFT_CLK_ENA
bool button_state_left(void);
#endif
#ifdef BTN_RIGHT_CLK_ENA
bool button_state_right(void);
#endif
#ifdef BTN_POWER_CLK_ENA
bool button_state_power(void);
#endif
#endif

View File

@ -20,6 +20,8 @@ def configure(env, features_wanted, defines, sources):
sources += ['embed/trezorhal/touch/touch.c', ]
sources += ['embed/trezorhal/touch/ft6x36.c', ]
features_available.append("touch")
sources += ['embed/trezorhal/button.c']
features_available.append("button")
if "sd_card" in features_wanted:
sources += ['embed/trezorhal/sdcard.c', ]