/* * device_handle.c * * Created on: 25 Aug 2023 * Author: malyarenko */ #include #include #include #include #include #include #include "service/sv_device_handle.h" #include "loader/ld_device_handle.h" #include "device.h" #include "device_desc.h" #include "device_handle.h" struct { uint32_t reset; uint32_t suspend; uint32_t resume; uint32_t disconnect; uint32_t config; uint32_t descriptor; uint32_t request; uint32_t ep; uint32_t device; } debug_handler_count = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; void efc_usb_device_handle_reset(void* instance) { debug_handler_count.reset += 1; if (instance == NULL) return; struct efc_usb_device_handler* const device_handler = instance; if (device_handler->current_config & EFC_USB_CONFIG_SV) { sv_device_handle_reset(&device_handler->config_handler.sv); return; } if (device_handler->current_config & EFC_USB_CONFIG_LD) { ld_device_handle_reset(&device_handler->config_handler.ld); return; } } void efc_usb_device_handle_suspend(void* instance) { debug_handler_count.suspend += 1; } void efc_usb_device_handle_resume(void* instance) { debug_handler_count.resume += 1; } void efc_usb_device_handle_disconnect(void* instance) { debug_handler_count.disconnect += 1; if (instance == NULL) return; struct efc_usb_device_handler* const device_handler = instance; if (device_handler->current_config == EFC_USB_CONFIG_SV) { sv_device_handle_disconnect(&device_handler->config_handler.sv); return; } if (device_handler->current_config & EFC_USB_CONFIG_LD) { device_handler->config_handler.ld.flags.connected = false; return; } } void efc_usb_device_handle_config_change(void* instance, uint32_t info) { debug_handler_count.config += 1; if (instance == NULL) return; struct efc_usb_device_handler* const device_handler = instance; /* Получить и обработать идентификатор новой конфигурации */ { const uint8_t new_config_id = (info & 0x0FU); const uint8_t new_config = (uint8_t) 0x01U << (new_config_id - 1); /* Некорректный идентификатор конфигурации */ if ((new_config_id == 0) || (new_config_id > EFC_USB_CONFIG_NUM)) return; /* Выбранная конфигуарция не была включена при инициализации */ if ((new_config & device_handler->enabled_config) == 0) return; } if (device_handler->current_config == EFC_USB_CONFIG_SV) { // TODO ld_device_handle_config_disbale(&device_handler->config_handler.ld); sv_device_handle_config_enable(&device_handler->config_handler.sv); return; } if (device_handler->current_config & EFC_USB_CONFIG_LD) { sv_device_handle_config_disable(&device_handler->config_handler.sv); ld_device_handle_config_change(&device_handler->config_handler.ld, info); device_handler->config_handler.ld.flags.connected = true; return; } } void efc_usb_device_handle_descriptor(void* instance, tUSBRequest* request) { debug_handler_count.descriptor += 1; if (instance == NULL) return; } void efc_usb_device_handle_request(void* instance, tUSBRequest* request) { debug_handler_count.request += 1; if (instance == NULL) return; } void efc_usb_device_handle_ep(void* instance, uint32_t status) { debug_handler_count.ep += 1; if (instance == NULL) return; struct efc_usb_device_handler* const device_handler = instance; if (device_handler->current_config == EFC_USB_CONFIG_SV) { sv_device_handle_ep(&device_handler->config_handler.sv, status); return; } if (device_handler->current_config & EFC_USB_CONFIG_LD) { ld_device_handle_ep(&device_handler->config_handler.ld, status); return; } } void efc_usb_device_handle(void* instance, uint32_t request, void* data) { debug_handler_count.device += 1; if (instance == NULL) return; }