mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-02 02:41:28 +00:00
trezorhal: make touch_init and usb_init return void, use ensure inside
This commit is contained in:
parent
5f256ce0b0
commit
3033762618
@ -161,7 +161,7 @@ void usb_init_all(void) {
|
||||
.report_desc = hid_report_desc,
|
||||
};
|
||||
|
||||
ensure(usb_init(&dev_info), NULL);
|
||||
usb_init(&dev_info);
|
||||
ensure(0 == usb_hid_add(&hid_info), NULL);
|
||||
usb_start();
|
||||
}
|
||||
@ -267,7 +267,7 @@ int main(void)
|
||||
|
||||
display_orientation(0);
|
||||
|
||||
ensure(touch_init(), NULL);
|
||||
touch_init();
|
||||
|
||||
// delay to detect touch
|
||||
uint32_t touched = 0;
|
||||
|
@ -439,9 +439,7 @@ STATIC mp_obj_t mod_trezorio_USB_open(mp_obj_t self) {
|
||||
mp_obj_get_array(MP_OBJ_FROM_PTR(&o->ifaces), &iface_cnt, &iface_objs);
|
||||
|
||||
// Initialize the USB stack
|
||||
if (usb_init(&o->info) != true) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "failed to initialize USB");
|
||||
}
|
||||
usb_init(&o->info);
|
||||
|
||||
int vcp_iface_num = -1;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../unix/common.h"
|
||||
#include "../../trezorhal/usb.h"
|
||||
#include "../../trezorhal/touch.h"
|
||||
|
||||
@ -23,13 +24,11 @@ static int sock;
|
||||
static struct sockaddr_in si_me, si_other;
|
||||
static socklen_t slen = 0;
|
||||
|
||||
bool usb_init(const usb_dev_info_t *dev_info) {
|
||||
void usb_init(const usb_dev_info_t *dev_info) {
|
||||
(void)dev_info;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock < 0) {
|
||||
return false;
|
||||
}
|
||||
ensure(sock >= 0, NULL);
|
||||
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
|
||||
@ -47,12 +46,7 @@ bool usb_init(const usb_dev_info_t *dev_info) {
|
||||
si_me.sin_port = htons(TREZOR_UDP_PORT);
|
||||
}
|
||||
|
||||
int b = bind(sock, (struct sockaddr*)&si_me, sizeof(si_me));
|
||||
if (b < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
ensure(0 == bind(sock, (struct sockaddr*)&si_me, sizeof(si_me)), NULL);
|
||||
}
|
||||
|
||||
void usb_deinit(void) {
|
||||
|
@ -28,7 +28,7 @@ int main(void)
|
||||
display_orientation(0);
|
||||
|
||||
sdcard_init();
|
||||
ensure(touch_init(), NULL);
|
||||
touch_init();
|
||||
|
||||
for (;;) {
|
||||
printf("CORE: Starting main loop\n");
|
||||
|
@ -8,13 +8,15 @@
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "touch.h"
|
||||
|
||||
I2C_HandleTypeDef i2c_handle = {
|
||||
.Instance = I2C1,
|
||||
};
|
||||
|
||||
bool touch_init(void)
|
||||
void touch_init(void)
|
||||
{
|
||||
// Enable I2C clock
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
@ -39,12 +41,7 @@ bool touch_init(void)
|
||||
init->NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
init->OwnAddress2 = 0;
|
||||
|
||||
// Init I2C handle
|
||||
if (HAL_I2C_Init(&i2c_handle) != HAL_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
ensure(HAL_I2C_Init(&i2c_handle) == HAL_OK, NULL);
|
||||
}
|
||||
|
||||
#define TOUCH_ADDRESS 56
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define TOUCH_MOVE 0x00020000
|
||||
#define TOUCH_END 0x00040000
|
||||
|
||||
bool touch_init(void);
|
||||
void touch_init(void);
|
||||
uint32_t touch_read(void);
|
||||
void touch_click(void);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "common.h"
|
||||
#include "usb.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
@ -41,15 +42,11 @@ static USBD_HandleTypeDef usb_dev_handle;
|
||||
static const USBD_DescriptorsTypeDef usb_descriptors;
|
||||
static const USBD_ClassTypeDef usb_class;
|
||||
|
||||
static int check_desc_str(const uint8_t *s) {
|
||||
if (!s || strlen((const char *)s) > USB_MAX_STR_SIZE) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
static bool check_desc_str(const uint8_t *s) {
|
||||
return s && strlen((const char *)s) <= USB_MAX_STR_SIZE;
|
||||
}
|
||||
|
||||
bool usb_init(const usb_dev_info_t *dev_info) {
|
||||
void usb_init(const usb_dev_info_t *dev_info) {
|
||||
|
||||
// Device descriptor
|
||||
usb_dev_desc.bLength = sizeof(usb_device_descriptor_t);
|
||||
@ -68,11 +65,10 @@ bool usb_init(const usb_dev_info_t *dev_info) {
|
||||
usb_dev_desc.bNumConfigurations = 1;
|
||||
|
||||
// String table
|
||||
if ((0 != check_desc_str(dev_info->manufacturer)) ||
|
||||
(0 != check_desc_str(dev_info->product)) ||
|
||||
(0 != check_desc_str(dev_info->serial_number))) {
|
||||
return false; // Invalid descriptor string
|
||||
}
|
||||
ensure(check_desc_str(dev_info->manufacturer), NULL);
|
||||
ensure(check_desc_str(dev_info->product), NULL);
|
||||
ensure(check_desc_str(dev_info->serial_number), NULL);
|
||||
|
||||
usb_str_table.manufacturer = dev_info->manufacturer;
|
||||
usb_str_table.product = dev_info->product;
|
||||
usb_str_table.serial_number = dev_info->serial_number;
|
||||
@ -90,14 +86,8 @@ bool usb_init(const usb_dev_info_t *dev_info) {
|
||||
// Pointer to interface descriptor data
|
||||
usb_next_iface_desc = (usb_interface_descriptor_t *)(usb_config_buf + usb_config_desc->wTotalLength);
|
||||
|
||||
if (0 != USBD_Init(&usb_dev_handle, (USBD_DescriptorsTypeDef*)&usb_descriptors, USB_PHY_ID)) {
|
||||
return false;
|
||||
}
|
||||
if (0 != USBD_RegisterClass(&usb_dev_handle, (USBD_ClassTypeDef*)&usb_class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
ensure(USBD_OK == USBD_Init(&usb_dev_handle, (USBD_DescriptorsTypeDef*)&usb_descriptors, USB_PHY_ID), NULL);
|
||||
ensure(USBD_OK == USBD_RegisterClass(&usb_dev_handle, (USBD_ClassTypeDef*)&usb_class), NULL);
|
||||
}
|
||||
|
||||
void usb_deinit(void) {
|
||||
|
@ -117,7 +117,7 @@ typedef struct {
|
||||
usb_iface_type_t type;
|
||||
} usb_iface_t;
|
||||
|
||||
bool usb_init(const usb_dev_info_t *dev_info);
|
||||
void usb_init(const usb_dev_info_t *dev_info);
|
||||
void usb_deinit(void);
|
||||
void usb_start(void);
|
||||
void usb_stop(void);
|
||||
|
Loading…
Reference in New Issue
Block a user