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