From 94f94260ace13688285fc8c62687079b26c18854 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 20 Dec 2020 15:18:02 +0100 Subject: Submodule-cache WIP --- fw/midi-dials/Src/curelib_src/curebuffer.c | 272 ---------- fw/midi-dials/Src/main.c | 220 -------- fw/midi-dials/Src/stm32f0xx_hal_msp.c | 191 ------- fw/midi-dials/Src/stm32f0xx_it.c | 176 ------- fw/midi-dials/Src/system_stm32f0xx.c | 265 ---------- fw/midi-dials/Src/usb_device.c | 132 ----- fw/midi-dials/Src/usbd_conf.c | 775 ----------------------------- fw/midi-dials/Src/usbd_desc.c | 365 -------------- fw/midi-dials/Src/usbd_midi_if.c | 480 ------------------ 9 files changed, 2876 deletions(-) delete mode 100644 fw/midi-dials/Src/curelib_src/curebuffer.c delete mode 100644 fw/midi-dials/Src/main.c delete mode 100644 fw/midi-dials/Src/stm32f0xx_hal_msp.c delete mode 100644 fw/midi-dials/Src/stm32f0xx_it.c delete mode 100644 fw/midi-dials/Src/system_stm32f0xx.c delete mode 100644 fw/midi-dials/Src/usb_device.c delete mode 100644 fw/midi-dials/Src/usbd_conf.c delete mode 100644 fw/midi-dials/Src/usbd_desc.c delete mode 100644 fw/midi-dials/Src/usbd_midi_if.c (limited to 'fw/midi-dials/Src') diff --git a/fw/midi-dials/Src/curelib_src/curebuffer.c b/fw/midi-dials/Src/curelib_src/curebuffer.c deleted file mode 100644 index 3792914..0000000 --- a/fw/midi-dials/Src/curelib_src/curebuffer.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - ******************************************************************************* - * [curebuffer.c] - * This module is for FIFO buffer. - * - * This program is under the terms of the GPLv3. - * https://www.gnu.org/licenses/gpl-3.0.html - * - * Copyright(c) 2017 Keshikan (www.keshikan.net) - ******************************************************************************* - */ - -#include "curebuffer.h" -#include -#include - - -///////////////////////////// -//methods for uint8_t FIFO. -///////////////////////////// - -BUFFER_STATUS cureRingBufferU8Init(RingBufferU8 *rbuf, uint16_t buflen) -{ - - uint32_t i; - - cureRingBufferU8Free(rbuf); - - rbuf->buffer = (uint8_t *)malloc( buflen * sizeof(uint8_t) ); - if(NULL == rbuf->buffer){ - return BUFFER_FAILURE; - } - for(i=0; ibuffer[i] = 0; - } - - rbuf->length = buflen; - - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBufferU8Free(RingBufferU8 *rbuf) -{ - if(NULL != rbuf->buffer){ - free(rbuf->buffer); - } - - rbuf->idx_front = rbuf->idx_rear = 0; - rbuf->length = 0; - - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBufferU8Enqueue(RingBufferU8 *rbuf, uint8_t *inputc) -{ - if( ((rbuf->idx_front +1)&(rbuf->length -1)) == rbuf->idx_rear ){//buffer overrun error occurs. - return BUFFER_FAILURE; - }else{ - - rbuf->buffer[rbuf->idx_front]= *inputc; - rbuf->idx_front++; - rbuf->idx_front &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - -BUFFER_STATUS cureRingBufferU8Dequeue(RingBufferU8 *rbuf, uint8_t *ret) -{ - if(rbuf->idx_front == rbuf->idx_rear){//if buffer underrun error occurs. - return BUFFER_FAILURE; - }else{ - - *ret = (rbuf->buffer[rbuf->idx_rear]); - rbuf->idx_rear++; - rbuf->idx_rear &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - -//debug -uint16_t _cureRingBufferU8GetUsedSize(RingBufferU8 *rbuf) -{ - if(rbuf->idx_front >= rbuf->idx_rear){ - return rbuf->idx_front - rbuf->idx_rear; - }else{ - return rbuf->idx_front + rbuf->length - rbuf->idx_rear; - } - -} - -///////////////////////////// -//methods for int16_t FIFO. -///////////////////////////// - -BUFFER_STATUS cureRingBuffer16Init(RingBuffer16 *rbuf, uint16_t buflen) -{ - - uint32_t i; - - cureRingBuffer16Free(rbuf); - - rbuf->buffer = (int16_t *)malloc( buflen * sizeof(int16_t) ); - if(NULL == rbuf->buffer){ - return BUFFER_FAILURE; - } - for(i=0; ibuffer[i] = 0; - } - rbuf->length = buflen; - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBuffer16Free(RingBuffer16 *rbuf) -{ - if(NULL != rbuf->buffer){ - free(rbuf->buffer); - } - - rbuf->idx_front = rbuf->idx_rear = 0; - rbuf->length = 0; - - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBuffer16Enqueue(RingBuffer16 *rbuf, int16_t *inputc) -{ - if( ((rbuf->idx_front +1)&(rbuf->length -1)) == rbuf->idx_rear ){//buffer overrun error occurs. - return BUFFER_FAILURE; - }else{ - rbuf->buffer[rbuf->idx_front]= *inputc; - rbuf->idx_front++; - rbuf->idx_front &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - -BUFFER_STATUS cureRingBuffer16EnqueueIgnoreErr(RingBuffer16 *rbuf, int16_t *inputc) -{ - - rbuf->buffer[rbuf->idx_front]= *inputc; - rbuf->idx_front++; - rbuf->idx_front &= (rbuf->length -1); - return BUFFER_SUCCESS; - -} - - -BUFFER_STATUS cureRingBuffer16Dequeue(RingBuffer16 *rbuf, int16_t *ret) -{ - if(rbuf->idx_front == rbuf->idx_rear){//if buffer underrun error occurs. - return BUFFER_FAILURE; - }else{ - *ret = (rbuf->buffer[rbuf->idx_rear]); - rbuf->idx_rear++; - rbuf->idx_rear &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - - -BUFFER_STATUS cureRingBuffer16GetElement(RingBuffer16 *rbuf, int16_t *ret, uint16_t delaynum, uint16_t delay_buffer_length) -{ - - if(rbuf->idx_front >= delaynum){ - rbuf->idx_rear = rbuf->idx_front - delaynum; - }else{ - rbuf->idx_rear = delay_buffer_length - (delaynum - rbuf->idx_front); - } - *ret = (rbuf->buffer[rbuf->idx_rear]); - return BUFFER_SUCCESS; - -} - -///////////////////////////// -//methods for uint32_t FIFO. -///////////////////////////// - -BUFFER_STATUS cureRingBufferU32Init(RingBuffer32 *rbuf, uint16_t buflen) -{ - - uint32_t i; - - cureRingBufferU32Free(rbuf); - - rbuf->buffer = (uint32_t *)malloc( buflen * sizeof(uint32_t) ); - if(NULL == rbuf->buffer){ - return BUFFER_FAILURE; - } - for(i=0; ibuffer[i] = 0; - } - rbuf->length = buflen; - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBufferU32Free(RingBuffer32 *rbuf) -{ - if(NULL != rbuf->buffer){ - free(rbuf->buffer); - } - - rbuf->idx_front = rbuf->idx_rear = 0; - rbuf->length = 0; - - return BUFFER_SUCCESS; -} - -BUFFER_STATUS cureRingBufferU32Enqueue(RingBuffer32 *rbuf, uint32_t *inputc) -{ - if( ((rbuf->idx_front +1)&(rbuf->length -1)) == rbuf->idx_rear ){//buffer overrun error occurs. - return BUFFER_FAILURE; - }else{ - rbuf->buffer[rbuf->idx_front]= *inputc; - rbuf->idx_front++; - rbuf->idx_front &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - -BUFFER_STATUS cureRingBufferU32EnqueueIgnoreErr(RingBuffer32 *rbuf, uint32_t *inputc) -{ - - rbuf->buffer[rbuf->idx_front]= *inputc; - rbuf->idx_front++; - rbuf->idx_front &= (rbuf->length -1); - return BUFFER_SUCCESS; - -} - - -BUFFER_STATUS cureRingBufferU32Dequeue(RingBuffer32 *rbuf, uint32_t *ret) -{ - if(rbuf->idx_front == rbuf->idx_rear){//if buffer underrun error occurs. - return BUFFER_FAILURE; - }else{ - *ret = (rbuf->buffer[rbuf->idx_rear]); - rbuf->idx_rear++; - rbuf->idx_rear &= (rbuf->length -1); - return BUFFER_SUCCESS; - } -} - - -BUFFER_STATUS cureRingBufferU32GetElement(RingBuffer32 *rbuf, uint32_t *ret, uint16_t delaynum, uint16_t delay_buffer_length) -{ - uint16_t buf; - - - if(rbuf->idx_front >= delaynum){ - buf = rbuf->idx_front - delaynum; - }else{ - buf = delay_buffer_length - (delaynum - rbuf->idx_front); - } - *ret = (rbuf->buffer[buf]); - return BUFFER_SUCCESS; - -} - - -//BUFFER_STATUS cureRingBufferU32GetElement(RingBuffer32 *rbuf, uint32_t *ret, uint16_t delaynum, uint16_t delay_buffer_length) -//{ -// -// -// if(rbuf->idx_front >= delaynum){ -// rbuf->idx_rear = rbuf->idx_front - delaynum; -// }else{ -// rbuf->idx_rear = delay_buffer_length - (delaynum - rbuf->idx_front); -// } -// *ret = (rbuf->buffer[rbuf->idx_rear]); -// return BUFFER_SUCCESS; -// -//} diff --git a/fw/midi-dials/Src/main.c b/fw/midi-dials/Src/main.c deleted file mode 100644 index a97c42d..0000000 --- a/fw/midi-dials/Src/main.c +++ /dev/null @@ -1,220 +0,0 @@ - -#include "main.h" -#include "usb_device.h" - -#include "device_conf.h" -#include "curemisc.h" -#include "curebuffer.h" -#include "usbd_midi_if.h" -#include "usbd_midi.h" - -#define HYST 50 - -ADC_HandleTypeDef hadc; -DMA_HandleTypeDef hdma_adc; - -PCD_HandleTypeDef hpcd_USB_FS; - -void SystemClock_Config(void); -static void MX_GPIO_Init(void); -static void MX_DMA_Init(void); -static void MX_ADC_Init(void); -static void MX_USB_PCD_Init(void); - -uint16_t ADC_val[8]; -uint16_t ADC_val_old[8]; -uint8_t dial[8]; -uint8_t dial_mapping[8] = {1, 2, 3, 4, 5, 6, 7, 0}; -uint16_t dial_div[8] = {32, 32, 32, 32, 32, 32, 32, 256}; - -uint8_t midi_packet[4] = {0x0B, 0xB0, 0x00, 0x00}; - -int main(void) -{ - HAL_Init(); - - SystemClock_Config(); - - MX_GPIO_Init(); - MX_DMA_Init(); - MX_ADC_Init(); - MX_USB_MIDI_INIT(); - - HAL_ADC_Start_DMA(&hadc, ADC_val, 8); - - - if(FUNC_ERROR == midiInit() ){ - while(1){ - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, SET); - HAL_Delay(500); - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, RESET); - HAL_Delay(500); - } - } - - //Wait usb configuration. - while(1){ - - if(USBD_STATE_CONFIGURED == hUsbDeviceFS.dev_state){ - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, SET); - break; - }else{ - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, RESET); - } - } - - while (1) - { - while(1){ - if(USBD_STATE_CONFIGURED == hUsbDeviceFS.dev_state){ - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, SET); - break; - }else{ - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, SET); - HAL_Delay(200); - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, RESET); - HAL_Delay(200); - } - } - - midiProcess(); - for(uint8_t i = 0; i <= 7; i++){ - if(ADC_val[dial_mapping[i]] >= (ADC_val_old[dial_mapping[i]] + HYST) || ADC_val[dial_mapping[i]] <= (ADC_val_old[dial_mapping[i]] - HYST)){ - ADC_val_old[dial_mapping[i]] = ADC_val[dial_mapping[i]]; - dial[i] = (uint8_t)((ADC_val[dial_mapping[i]]/dial_div[i]) & 0x7F); - midi_packet[3] = dial[i]; - midi_packet[1] = 0xB0 + i; - sendMidiMessage(midi_packet, 4); - USBD_MIDI_SendPacket(); - HAL_Delay(2); - } - } - //USBD_MIDI_SendData(&hUsbDeviceFS, midi_packet, 4); - - - } -} - -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; - RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; - RCC_OscInitStruct.HSI14CalibrationValue = 16; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); - - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); - -} - -static void MX_ADC_Init(void) -{ - - ADC_ChannelConfTypeDef sConfig = {0}; - - hadc.Instance = ADC1; - hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; - hadc.Init.Resolution = ADC_RESOLUTION_12B; - hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; - hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV; - hadc.Init.LowPowerAutoWait = DISABLE; - hadc.Init.LowPowerAutoPowerOff = DISABLE; - hadc.Init.ContinuousConvMode = ENABLE; - hadc.Init.DiscontinuousConvMode = DISABLE; - hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc.Init.DMAContinuousRequests = ENABLE; - hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; - HAL_ADC_Init(&hadc); - - sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; - sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; - sConfig.Channel = ADC_CHANNEL_1; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_2; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_3; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_4; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_5; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_6; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_7; - HAL_ADC_ConfigChannel(&hadc, &sConfig); - - sConfig.Channel = ADC_CHANNEL_8; - HAL_ADC_ConfigChannel(&hadc, &sConfig); -} - -static void MX_USB_PCD_Init(void) -{ - - hpcd_USB_FS.Instance = USB; - hpcd_USB_FS.Init.dev_endpoints = 8; - hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_FS.Init.low_power_enable = DISABLE; - hpcd_USB_FS.Init.lpm_enable = DISABLE; - hpcd_USB_FS.Init.battery_charging_enable = DISABLE; - HAL_PCD_Init(&hpcd_USB_FS); -} - - -static void MX_DMA_Init(void) -{ - __HAL_RCC_DMA1_CLK_ENABLE(); - - HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); -} - - -static void MX_GPIO_Init(void) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); - - GPIO_InitStruct.Pin = GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -} - -void Error_Handler(void) -{ - while(1){ - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,1); - HAL_Delay(100); - HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,0); - HAL_Delay(100); - } -} diff --git a/fw/midi-dials/Src/stm32f0xx_hal_msp.c b/fw/midi-dials/Src/stm32f0xx_hal_msp.c deleted file mode 100644 index 8695580..0000000 --- a/fw/midi-dials/Src/stm32f0xx_hal_msp.c +++ /dev/null @@ -1,191 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * File Name : stm32f0xx_hal_msp.c - * Description : This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ -extern DMA_HandleTypeDef hdma_adc; - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN Define */ - -/* USER CODE END Define */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN Macro */ - -/* USER CODE END Macro */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* External functions --------------------------------------------------------*/ -/* USER CODE BEGIN ExternalFunctions */ - -/* USER CODE END ExternalFunctions */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ -/** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); - - /* System interrupt init*/ - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/** -* @brief ADC MSP Initialization -* This function configures the hardware resources used in this example -* @param hadc: ADC handle pointer -* @retval None -*/ -void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hadc->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspInit 0 */ - - /* USER CODE END ADC1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_ADC1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**ADC GPIO Configuration - PA0 ------> ADC_IN0 - PA1 ------> ADC_IN1 - PA2 ------> ADC_IN2 - PA3 ------> ADC_IN3 - PA4 ------> ADC_IN4 - PA5 ------> ADC_IN5 - PA6 ------> ADC_IN6 - PA7 ------> ADC_IN7 - PB0 ------> ADC_IN8 - */ - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 - |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_0; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - /* ADC Init */ - hdma_adc.Instance = DMA1_Channel1; - hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; - hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_adc.Init.MemInc = DMA_MINC_ENABLE; - hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; - hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; - hdma_adc.Init.Mode = DMA_CIRCULAR; - hdma_adc.Init.Priority = DMA_PRIORITY_MEDIUM; - if (HAL_DMA_Init(&hdma_adc) != HAL_OK) - { - Error_Handler(); - } - - __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc); - - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } - -} - -/** -* @brief ADC MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param hadc: ADC handle pointer -* @retval None -*/ -void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) -{ - if(hadc->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ - - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC1_CLK_DISABLE(); - - /**ADC GPIO Configuration - PA0 ------> ADC_IN0 - PA1 ------> ADC_IN1 - PA2 ------> ADC_IN2 - PA3 ------> ADC_IN3 - PA4 ------> ADC_IN4 - PA5 ------> ADC_IN5 - PA6 ------> ADC_IN6 - PA7 ------> ADC_IN7 - PB0 ------> ADC_IN8 - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 - |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); - - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0); - - /* ADC1 DMA DeInit */ - HAL_DMA_DeInit(hadc->DMA_Handle); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ - - /* USER CODE END ADC1_MspDeInit 1 */ - } - -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/fw/midi-dials/Src/stm32f0xx_it.c b/fw/midi-dials/Src/stm32f0xx_it.c deleted file mode 100644 index 3d94908..0000000 --- a/fw/midi-dials/Src/stm32f0xx_it.c +++ /dev/null @@ -1,176 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32f0xx_it.h" -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* External variables --------------------------------------------------------*/ -extern DMA_HandleTypeDef hdma_adc; -extern PCD_HandleTypeDef hpcd_USB_FS; - -/* USER CODE BEGIN EV */ - -/* USER CODE END EV */ - -/******************************************************************************/ -/* Cortex-M0 Processor Interruption and Exception Handlers */ -/******************************************************************************/ -/** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - - /* USER CODE END NonMaskableInt_IRQn 1 */ -} - -/** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } -} - -/** - * @brief This function handles System service call via SWI instruction. - */ -void SVC_Handler(void) -{ - /* USER CODE BEGIN SVC_IRQn 0 */ - - /* USER CODE END SVC_IRQn 0 */ - /* USER CODE BEGIN SVC_IRQn 1 */ - - /* USER CODE END SVC_IRQn 1 */ -} - -/** - * @brief This function handles Pendable request for system service. - */ -void PendSV_Handler(void) -{ - /* USER CODE BEGIN PendSV_IRQn 0 */ - - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ - - /* USER CODE END PendSV_IRQn 1 */ -} - -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - -/******************************************************************************/ -/* STM32F0xx Peripheral Interrupt Handlers */ -/* Add here the Interrupt Handlers for the used peripherals. */ -/* For the available peripheral interrupt handler names, */ -/* please refer to the startup file (startup_stm32f0xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles DMA1 channel 1 global interrupt. - */ -void DMA1_Channel1_IRQHandler(void) -{ - /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */ - - /* USER CODE END DMA1_Channel1_IRQn 0 */ - HAL_DMA_IRQHandler(&hdma_adc); - /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */ - - /* USER CODE END DMA1_Channel1_IRQn 1 */ -} - -/** -* @brief This function handles USB global Interrupt / USB wake-up interrupt through EXTI line 18. -*/ -void USB_IRQHandler(void) -{ - /* USER CODE BEGIN USB_IRQn 0 */ - - /* USER CODE END USB_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_FS); - /* USER CODE BEGIN USB_IRQn 1 */ - - /* USER CODE END USB_IRQn 1 */ -} - - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/fw/midi-dials/Src/system_stm32f0xx.c b/fw/midi-dials/Src/system_stm32f0xx.c deleted file mode 100644 index 6a3202b..0000000 --- a/fw/midi-dials/Src/system_stm32f0xx.c +++ /dev/null @@ -1,265 +0,0 @@ -/** - ****************************************************************************** - * @file system_stm32f0xx.c - * @author MCD Application Team - * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File. - * - * 1. This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32f0xx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * 2. After each device reset the HSI (8 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32f0xx.s" file, to - * configure the system clock before to branch to main program. - * - * 3. This file configures the system clock as follows: - *============================================================================= - * Supported STM32F0xx device - *----------------------------------------------------------------------------- - * System Clock source | HSI - *----------------------------------------------------------------------------- - * SYSCLK(Hz) | 8000000 - *----------------------------------------------------------------------------- - * HCLK(Hz) | 8000000 - *----------------------------------------------------------------------------- - * AHB Prescaler | 1 - *----------------------------------------------------------------------------- - * APB1 Prescaler | 1 - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2016 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32f0xx_system - * @{ - */ - -/** @addtogroup STM32F0xx_System_Private_Includes - * @{ - */ - -#include "stm32f0xx.h" - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Defines - * @{ - */ -#if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. - This value can be provided and adapted by the user application. */ -#endif /* HSE_VALUE */ - -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. - This value can be provided and adapted by the user application. */ -#endif /* HSI_VALUE */ - -#if !defined (HSI48_VALUE) -#define HSI48_VALUE ((uint32_t)48000000) /*!< Default value of the HSI48 Internal oscillator in Hz. - This value can be provided and adapted by the user application. */ -#endif /* HSI48_VALUE */ -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Variables - * @{ - */ - /* This variable is updated in three ways: - 1) by calling CMSIS function SystemCoreClockUpdate() - 2) by calling HAL API function HAL_RCC_GetHCLKFreq() - 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency - Note: If you use this function to configure the system clock there is no need to - call the 2 first functions listed above, since SystemCoreClock variable is - updated automatically. - */ -uint32_t SystemCoreClock = 8000000; - -const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; -const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Functions - * @{ - */ - -/** - * @brief Setup the microcontroller system. - * @param None - * @retval None - */ -void SystemInit(void) -{ - /* NOTE :SystemInit(): This function is called at startup just after reset and - before branch to main program. This call is made inside - the "startup_stm32f0xx.s" file. - User can setups the default system clock (System clock source, PLL Multiplier - and Divider factors, AHB/APBx prescalers and Flash settings). - */ -} - -/** - * @brief Update SystemCoreClock variable according to Clock Register Values. - * The SystemCoreClock variable contains the core clock (HCLK), it can - * be used by the user application to setup the SysTick timer or configure - * other parameters. - * - * @note Each time the core clock (HCLK) changes, this function must be called - * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined - * constant and the selected clock source: - * - * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) - * or HSI_VALUE(*) multiplied/divided by the PLL factors. - * - * (*) HSI_VALUE is a constant defined in stm32f0xx_hal.h file (default value - * 8 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (**) HSE_VALUE is a constant defined in stm32f0xx_hal.h file (default value - * 8 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ -void SystemCoreClockUpdate (void) -{ - uint32_t tmp = 0, pllmull = 0, pllsource = 0, predivfactor = 0; - - /* Get SYSCLK source -------------------------------------------------------*/ - tmp = RCC->CFGR & RCC_CFGR_SWS; - - switch (tmp) - { - case RCC_CFGR_SWS_HSI: /* HSI used as system clock */ - SystemCoreClock = HSI_VALUE; - break; - case RCC_CFGR_SWS_HSE: /* HSE used as system clock */ - SystemCoreClock = HSE_VALUE; - break; - case RCC_CFGR_SWS_PLL: /* PLL used as system clock */ - /* Get PLL clock source and multiplication factor ----------------------*/ - pllmull = RCC->CFGR & RCC_CFGR_PLLMUL; - pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; - pllmull = ( pllmull >> 18) + 2; - predivfactor = (RCC->CFGR2 & RCC_CFGR2_PREDIV) + 1; - - if (pllsource == RCC_CFGR_PLLSRC_HSE_PREDIV) - { - /* HSE used as PLL clock source : SystemCoreClock = HSE/PREDIV * PLLMUL */ - SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull; - } -#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) - else if (pllsource == RCC_CFGR_PLLSRC_HSI48_PREDIV) - { - /* HSI48 used as PLL clock source : SystemCoreClock = HSI48/PREDIV * PLLMUL */ - SystemCoreClock = (HSI48_VALUE/predivfactor) * pllmull; - } -#endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx */ - else - { -#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6) \ - || defined(STM32F078xx) || defined(STM32F071xB) || defined(STM32F072xB) \ - || defined(STM32F070xB) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC) - /* HSI used as PLL clock source : SystemCoreClock = HSI/PREDIV * PLLMUL */ - SystemCoreClock = (HSI_VALUE/predivfactor) * pllmull; -#else - /* HSI used as PLL clock source : SystemCoreClock = HSI/2 * PLLMUL */ - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; -#endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || - STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || - STM32F091xC || STM32F098xx || STM32F030xC */ - } - break; - default: /* HSI used as system clock */ - SystemCoreClock = HSI_VALUE; - break; - } - /* Compute HCLK clock frequency ----------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/fw/midi-dials/Src/usb_device.c b/fw/midi-dials/Src/usb_device.c deleted file mode 100644 index 8afc228..0000000 --- a/fw/midi-dials/Src/usb_device.c +++ /dev/null @@ -1,132 +0,0 @@ -/** - ****************************************************************************** - * @file : usb_device.c - * @version : v2.0_Cube - * @brief : This file implements the USB Device - ****************************************************************************** - * This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * Copyright (c) 2018 STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ - -#include "usb_device.h" -#include "usbd_core.h" -#include "usbd_desc.h" - -/* USER CODE BEGIN Includes */ -#include "usbd_midi.h" -#include "usbd_midi_if.h" - -/* USER CODE END Includes */ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* USB Device Core handle declaration. */ -USBD_HandleTypeDef hUsbDeviceFS; - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* - * -- Insert your external function declaration here -- - */ -/* USER CODE BEGIN 1 */ - -void MX_USB_MIDI_INIT(void) -{ - USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); - - USBD_RegisterClass(&hUsbDeviceFS, &USBD_MIDI); - - USBD_MIDI_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); - - USBD_Start(&hUsbDeviceFS); -} - -/* USER CODE END 1 */ - -/** - * Init USB device Library, add supported class and start the library - * @retval None - */ -void MX_USB_DEVICE_Init(void) -{ - /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ -#ifdef USBMIDI - /* USER CODE END USB_DEVICE_Init_PreTreatment */ - - /* Init Device Library, add supported class and start the library. */ - USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); - - USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); - - USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); - - USBD_Start(&hUsbDeviceFS); - - /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ -#endif - /* USER CODE END USB_DEVICE_Init_PostTreatment */ -} - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/fw/midi-dials/Src/usbd_conf.c b/fw/midi-dials/Src/usbd_conf.c deleted file mode 100644 index cb09894..0000000 --- a/fw/midi-dials/Src/usbd_conf.c +++ /dev/null @@ -1,775 +0,0 @@ -/** - ****************************************************************************** - * @file : usbd_conf.c - * @version : v2.0_Cube - * @brief : This file implements the board support package for the USB device library - ****************************************************************************** - * This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * Copyright (c) 2018 STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f0xx.h" -#include "stm32f0xx_hal.h" -#include "usbd_def.h" -#include "usbd_core.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -PCD_HandleTypeDef hpcd_USB_FS; -//void _Error_Handler(char * file, int line); - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* Private functions ---------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); -//extern void SystemClock_Config(void); - -/******************************************************************************* - LL Driver Callbacks (PCD -> USB Device Library) -*******************************************************************************/ -/* MSP Init */ - -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB) - { - /* USER CODE BEGIN USB_MspInit 0 */ - - /* USER CODE END USB_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_USB_CLK_ENABLE(); - - /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(USB_IRQn, 1, 0); - HAL_NVIC_EnableIRQ(USB_IRQn); - /* USER CODE BEGIN USB_MspInit 1 */ - - /* USER CODE END USB_MspInit 1 */ - } -} - -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB) - { - /* USER CODE BEGIN USB_MspDeInit 0 */ - - /* USER CODE END USB_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_CLK_DISABLE(); - - /* Peripheral interrupt Deinit*/ - HAL_NVIC_DisableIRQ(USB_IRQn); - - /* USER CODE BEGIN USB_MspDeInit 1 */ - - /* USER CODE END USB_MspDeInit 1 */ - } -} - -/** - * @brief Setup stage callback - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) -{ - USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); -} - -/** - * @brief Data Out stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -{ - USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); -} - -/** - * @brief Data In stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -{ - USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); -} - -/** - * @brief SOF callback. - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) -{ - USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); -} - -/** - * @brief Reset callback. - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) -{ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - - /* Set USB current speed. */ - switch (hpcd->Init.speed) - { - case PCD_SPEED_FULL: - speed = USBD_SPEED_FULL; - break; - - default: - speed = USBD_SPEED_FULL; - break; - } - USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); - - /* Reset Device. */ - USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); -} - -/** - * @brief Suspend callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) -{ - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - if (hpcd->Init.low_power_enable) - { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - /* USER CODE END 2 */ -} - -/** - * @brief Resume callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) -{ - /* USER CODE BEGIN 3 */ - - /* USER CODE END 3 */ - USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); -} - -/** - * @brief ISOOUTIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -{ - USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); -} - -/** - * @brief ISOINIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -{ - USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); -} - -/** - * @brief Connect callback. - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) -{ - USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); -} - -/** - * @brief Disconnect callback. - * @param hpcd: PCD handle - * @retval None - */ -void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) -{ - USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); -} - -/******************************************************************************* - LL Driver Interface (USB Device Library --> PCD) -*******************************************************************************/ - -/** - * @brief Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) -{ - /* Init USB Ip. */ - /* Link the driver to the stack. */ - hpcd_USB_FS.pData = pdev; - pdev->pData = &hpcd_USB_FS; - - hpcd_USB_FS.Instance = USB; - hpcd_USB_FS.Init.dev_endpoints = 8; - hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64; - hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_FS.Init.low_power_enable = DISABLE; - hpcd_USB_FS.Init.lpm_enable = DISABLE; - hpcd_USB_FS.Init.battery_charging_enable = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) - { - //_Error_Handler(__FILE__, __LINE__); - } - - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); - return USBD_OK; -} - -/** - * @brief De-Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_DeInit(pdev->pData); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Starts the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Start(pdev->pData); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Stops the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Stop(pdev->pData); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Opens an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param ep_type: Endpoint type - * @param ep_mps: Endpoint max packet size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Closes an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Flushes an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Sets a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Clears a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Returns Stall condition. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Stall (1: Yes, 0: No) - */ -uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; - - if((ep_addr & 0x80) == 0x80) - { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } - else - { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } -} - -/** - * @brief Assigns a USB address to the device. - * @param pdev: Device handle - * @param dev_addr: Device address - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Transmits data over an endpoint. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be sent - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Prepares an endpoint for reception. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be received - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/** - * @brief Returns the last transfered packet size. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Recived Data Size - */ -uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); -} - -/** - * @brief Delays routine for the USB device library. - * @param Delay: Delay in ms - * @retval None - */ -void USBD_LL_Delay(uint32_t Delay) -{ - HAL_Delay(Delay); -} - -/** - * @brief Static single allocation. - * @param size: Size of allocated memory - * @retval None - */ -//void *USBD_static_malloc(uint32_t size) -//{ -// static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ -// return mem; -//} - -/** - * @brief Dummy memory free - * @param p: Pointer to allocated memory address - * @retval None - */ -void USBD_static_free(void *p) -{ - -} - -/* USER CODE BEGIN 5 */ -/** - * @brief Configures system clock after wake-up from USB Resume CallBack: - * enable HSI, PLL and select PLL as system clock source. - * @retval None - */ -//static void SystemClockConfig_Resume(void) -//{ -// SystemClock_Config(); -//} -/* USER CODE END 5 */ - -/** - * @brief Software device connection - * @param hpcd: PCD handle - * @param state: Connection state (0: disconnected / 1: connected) - * @retval None - */ -void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) -{ - /* USER CODE BEGIN 6 */ - if (state == 1) - { - /* Configure Low connection state. */ - - } - else - { - /* Configure High connection state */ - - } - /* USER CODE END 6 */ -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/fw/midi-dials/Src/usbd_desc.c b/fw/midi-dials/Src/usbd_desc.c deleted file mode 100644 index 0304366..0000000 --- a/fw/midi-dials/Src/usbd_desc.c +++ /dev/null @@ -1,365 +0,0 @@ -/** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v2.0_Cube - * @brief : This file implements the USB device descriptors. - ****************************************************************************** - * This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * Copyright (c) 2018 STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_conf.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @addtogroup USBD_DESC - * @{ - */ - -/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines - * @brief Private defines. - * @{ - */ - -/* - *************************************************[ATTENTION]************************************************ - * - * VID 0x1209 and PID 0x0001 is experimental IDs from http://pid.codes . - * You must get your own IDs, and change to your own IDs in order to avoid conflicting to other USB devices. - * - ************************************************************************************************************ -*/ - -#define USBD_VID 0x1209 //MUST BE CHANGED. -#define USBD_LANGID_STRING 1041 -#define USBD_MANUFACTURER_STRING "Otter Scientific" -#define USBD_PID_FS 0x0001 //MUST BE CHANGED. -#define USBD_PRODUCT_STRING_FS "MIDI Dials" -#define USBD_SERIALNUMBER_STRING_FS "00000000001A" -#define USBD_CONFIGURATION_STRING_FS "MIDI Config" -#define USBD_INTERFACE_STRING_FS "MIDI Interface" - - - -/* USER CODE BEGIN PRIVATE_DEFINES */ - -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); - -#ifdef USB_SUPPORT_USER_STRING_DESC -uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); -#endif /* USB_SUPPORT_USER_STRING_DESC */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -USBD_DescriptorsTypeDef FS_Desc = -{ - USBD_FS_DeviceDescriptor -, USBD_FS_LangIDStrDescriptor -, USBD_FS_ManufacturerStrDescriptor -, USBD_FS_ProductStrDescriptor -, USBD_FS_SerialStrDescriptor -, USBD_FS_ConfigStrDescriptor -, USBD_FS_InterfaceStrDescriptor -}; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -/** USB standard device descriptor. */ -__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = -{ - 0x12, /*bLength */ - USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ - 0x00, /*bcdUSB */ - 0x02, - 0x02, /*bDeviceClass*/ - 0x02, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID_FS), /*idProduct*/ - HIBYTE(USBD_PID_FS), /*idProduct*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ -}; - -/* USB_DeviceDescriptor */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ - -/** USB lang indentifier descriptor. */ -__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = -{ - USB_LEN_LANGID_STR_DESC, - USB_DESC_TYPE_STRING, - LOBYTE(USBD_LANGID_STRING), - HIBYTE(USBD_LANGID_STRING) -}; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -/* Internal string descriptor. */ -__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions - * @brief Private functions. - * @{ - */ - -/** - * @brief Return the device descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - *length = sizeof(USBD_FS_DeviceDesc); - return USBD_FS_DeviceDesc; -} - -/** - * @brief Return the LangID string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; -} - -/** - * @brief Return the product string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the manufacturer string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; -} - -/** - * @brief Return the serial number string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the configuration string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the interface string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/fw/midi-dials/Src/usbd_midi_if.c b/fw/midi-dials/Src/usbd_midi_if.c deleted file mode 100644 index bbcbf97..0000000 --- a/fw/midi-dials/Src/usbd_midi_if.c +++ /dev/null @@ -1,480 +0,0 @@ -/** - ****************************************************************************** - * @file : usbd_midi_if.c - * @brief : - ****************************************************************************** - - (CC at)2016 by D.F.Mac. @TripArts Music - - ****************************************************************************** - - Modified by keshikan (www.keshikan.net) 2018 - The license is (CC BY 4.0), and takes over from original usbd_midi_if.h/c. - - See also original source code page. - https://github.com/mimuz/mimuz-tuch/blob/master/STM32/ - - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_midi_if.h" -#include "stm32f0xx_hal.h" - - -// basic midi rx/tx functions -static uint16_t MIDI_DataRx(uint8_t *msg, uint16_t length); -static uint16_t MIDI_DataTx(uint8_t *msg, uint16_t length); - -// for Cure Series -#define MIDI_BUFFER_SIZ (512)//FIFO buffer byte size for midi message buffer - -RingBufferU8 rbuf_usb_rx[MIDI_OUT_JACK_NUM]; //for input from USB -RingBufferU8 rbuf_jack_rx[MIDI_IN_JACK_NUM]; //for input from MIDI-IN jack - -//for receiving midi data from jack -MidiAnalysisStatus analyzed_status[MIDI_IN_JACK_NUM]; -MIDIEvent midi_event[MIDI_IN_JACK_NUM]; //received midi data - -uint8_t rx_midi_msg[MIDI_IN_JACK_NUM]; - - -FUNC_STATUS midiInit() -{ - uint32_t i,j; - - for(i=0; i> 4; - uint8_t code_idx_num = msg[0 + 4*cnt_msgs] & 0x0F; - - switch (code_idx_num) { - - //not defined - case 0x0: - case 0x1: - midi_size = 0; - break; - - //1byte message - case 0x5: - case 0xF: - midi_size = 1; - break; - - //2byte message - case 0x2: - case 0x6: - case 0xC: - case 0xD: - midi_size = 2; - break; - - //3byte message - case 0x3: - case 0x4: - case 0x7: - case 0x8: - case 0x9: - case 0xA: - case 0xB: - case 0xE: - midi_size = 3; - break; - - default: - midi_size = 0; - break; - } - - for(cnt = 0;cnt < midi_size;cnt ++){ - u8b = *(msg + 4*cnt_msgs + cnt + 1); - cureRingBufferU8Enqueue(&rbuf_usb_rx[cable_num], &u8b); - } - } - - return 0; -} - -void sendMidiMessage(uint8_t *msg, uint16_t size){ - if(size == 4){ -// APP_Rx_Buffer[0] = msg[0]; -// APP_Rx_Buffer[1] = msg[1]; -// APP_Rx_Buffer[2] = msg[2]; -// APP_Rx_Buffer[3] = msg[3]; -// USBD_MIDI_SendData(&hUsbDeviceFS, APP_Rx_Buffer, size); - MIDI_DataTx(msg, size); - } -} - -static uint16_t MIDI_DataTx(uint8_t *msg, uint16_t length){ - uint32_t i = 0; - while (i < length) { - APP_Rx_Buffer[APP_Rx_ptr_in] = *(msg + i); - APP_Rx_ptr_in++; - i++; - if (APP_Rx_ptr_in == APP_RX_DATA_SIZE) { - APP_Rx_ptr_in = 0; - } - } - return USBD_OK; -} - -bool midiEventIsGenerated(uint8_t cable_num) -{ - uint8_t upper_half_byte= (rx_midi_msg[cable_num]) & 0xF0; - - if( upper_half_byte & 0x80 ){//0x80-0xFF:status byte - - switch(upper_half_byte){ - - case 0xF0://0xF0-0xFF:system message - switch(rx_midi_msg[cable_num]){ - - case 0xF0://SysEx Start - analyzed_status[cable_num].data_idx = 0; - midi_event[cable_num].midi_byte[ analyzed_status[cable_num].data_idx++ ] = rx_midi_msg[cable_num]; - analyzed_status[cable_num].type = MSG_SYSEX; - analyzed_status[cable_num].stat = WAIT_SYSTEM_DATA; - break; - - case 0xF7://SysEx End - midi_event[cable_num].midi_byte[ analyzed_status[cable_num].data_idx++ ] = rx_midi_msg[cable_num]; - midi_event[cable_num].length = analyzed_status[cable_num].data_idx; - analyzed_status[cable_num].stat = END_ANALYSIS; - break; - - case 0xF2://Song Position - midi_event[cable_num].midi_byte[0] = rx_midi_msg[cable_num]; - analyzed_status[cable_num].type = MSG_THREE_BYTE; - analyzed_status[cable_num].stat = WAIT_DATA1; - break; - - case 0xF1://Time Code - case 0xF3://Song Select - midi_event[cable_num].midi_byte[0] = rx_midi_msg[cable_num]; - analyzed_status[cable_num].type = MSG_TWO_BYTE; - analyzed_status[cable_num].stat = WAIT_DATA1; - break; - - case 0xF4://Undefined - case 0xF5://Undefined - case 0xF6://Tune request - case 0xF8://Timing clock - case 0xF9://Undefined - case 0xFA://Start - case 0xFB://Continue - case 0xFC://Stop - case 0xFD://Undefined - case 0xFE://Active Sensing - case 0xFF://Reset - midi_event[cable_num].midi_byte[0] = rx_midi_msg[cable_num]; - midi_event[cable_num].length = 1; - analyzed_status[cable_num].type = MSG_ONE_BYTE; - analyzed_status[cable_num].stat = END_ANALYSIS; - break; - } - analyzed_status[cable_num].is_system_common = true; - break; - - case 0x80://Note Off - case 0x90://Note On - case 0xA0://Polyphonic key-pressure - case 0xB0://ControlChange - case 0xE0://PitchBend - midi_event[cable_num].midi_byte[0] = rx_midi_msg[cable_num]; - analyzed_status[cable_num].type = MSG_THREE_BYTE; - analyzed_status[cable_num].stat = WAIT_DATA1; - analyzed_status[cable_num].is_system_common = false; - break; - - case 0xC0://Program Change - case 0xD0://Channel pressure - midi_event[cable_num].midi_byte[0] = rx_midi_msg[cable_num]; - analyzed_status[cable_num].type = MSG_TWO_BYTE; - analyzed_status[cable_num].stat = WAIT_DATA1; - analyzed_status[cable_num].is_system_common = false; - break; - - default: - analyzed_status[cable_num].type = MSG_NOTHING; - analyzed_status[cable_num].stat = START_ANALYSIS; - analyzed_status[cable_num].is_system_common = false; - break; - } - - }else{//0x00-0x7F:data byte - - switch(analyzed_status[cable_num].stat){ - - case WAIT_DATA1: - midi_event[cable_num].midi_byte[1] = rx_midi_msg[cable_num]; - - if(MSG_THREE_BYTE == analyzed_status[cable_num].type ){ - analyzed_status[cable_num].stat = WAIT_DATA2; - }else if( MSG_TWO_BYTE == analyzed_status[cable_num].type ){ - midi_event[cable_num].length = 2; - analyzed_status[cable_num].stat = END_ANALYSIS; - }else{ - analyzed_status[cable_num].stat = START_ANALYSIS; - } - break; - - case WAIT_DATA2: - if(MSG_THREE_BYTE == analyzed_status[cable_num].type ){ - midi_event[cable_num].midi_byte[2] = rx_midi_msg[cable_num]; - midi_event[cable_num].length = 3; - analyzed_status[cable_num].stat = END_ANALYSIS; - }else{ - analyzed_status[cable_num].stat = START_ANALYSIS; - } - break; - - case WAIT_SYSTEM_DATA: - midi_event[cable_num].midi_byte[ analyzed_status[cable_num].data_idx++ ] = rx_midi_msg[cable_num]; - - if(analyzed_status[cable_num].data_idx > (MIDI_SENDDATA_MAX - 1) ){ - analyzed_status[cable_num].stat = END_ANALYSIS; - } - break; - - case END_ANALYSIS://running status:When status byte is omitted. - midi_event[cable_num].midi_byte[1] = rx_midi_msg[cable_num]; - if(MSG_THREE_BYTE == analyzed_status[cable_num].type){ - analyzed_status[cable_num].stat = WAIT_DATA2; - }else if(MSG_TWO_BYTE == analyzed_status[cable_num].type){ - midi_event[cable_num].length = 2; - analyzed_status[cable_num].stat = END_ANALYSIS; - } - break; - - case START_ANALYSIS: - break; - - default: - break; - } - } - - if(END_ANALYSIS == analyzed_status[cable_num].stat){ - return true; - }else{ - return false; - } - -} - - -void midiGenerateUsbPacket(uint8_t cable_num) -{ - uint8_t msg_buf[4] = {0x00,0x00,0x00,0x00}; - uint32_t cnt_remain=0, cnt_length; - - switch(analyzed_status[cable_num].type){ - - case MSG_ONE_BYTE: - //byte 0: cable number + code index number - msg_buf[0] = (cable_num << 4) + ((midi_event[cable_num].midi_byte[0] & 0xF0) >> 4); - - sendMidiMessage(msg_buf,4); - break; - - case MSG_TWO_BYTE: - case MSG_THREE_BYTE: - //byte 0: cable number + code index number - if(analyzed_status[cable_num].is_system_common){ - msg_buf[0] = (cable_num << 4) + midi_event[cable_num].length; - }else{ - msg_buf[0] = (cable_num << 4) + ((midi_event[cable_num].midi_byte[0] & 0xF0) >> 4); - } - - //byte 1-3 - for(uint32_t i=0; i=3){ - cnt_remain = 0; - } - } - break; - - default: - break; - } - USBD_MIDI_SendPacket(); -} - -void midiProcess(){ - - for(uint32_t cable_num=0; cable_num