This commit is contained in:
ChrisMicro 2017-05-23 07:16:14 +02:00
commit ceed2c4e91
10 changed files with 20 additions and 30 deletions

View File

@ -68,8 +68,8 @@ void yield(void);
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define interrupts() __enable_irq()
#define noInterrupts() __disable_irq()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )

View File

@ -48,7 +48,13 @@ int main(void)
initVariant();
#if defined(USB_BASE) || defined(USB_OTG_DEVICE_BASE)
USBDeviceFS.beginMenuSelection();
#ifdef MENU_USB_SERIAL
USBDeviceFS.beginCDC();
#elif MENU_USB_MASS_STORAGE
USBDeviceFS.beginMSC();
#endif
#endif
setup();

View File

@ -62,18 +62,6 @@ void USBDeviceClass::reenumerate() {
#endif
}
bool USBDeviceClass::beginMenuSelection() {
#ifdef MENU_USB_SERIAL
return beginCDC();
#elif MENU_USB_MASS_STORAGE
return beginMSC();
#else
return false;
#endif
}
bool USBDeviceClass::beginCDC() {
reenumerate();

View File

@ -29,8 +29,6 @@ class USBDeviceClass {
public:
void reenumerate();
bool beginMenuSelection();
bool beginCDC();
bool beginMSC();

View File

@ -82,7 +82,7 @@ void analogWrite(uint8_t pin, int value) {
HAL_TIM_Base_Start_IT(handle);
}
for(int i=0; i<sizeof(pwm_config) / sizeof(pwm_config[0]); i++) {
for(size_t i=0; i<sizeof(pwm_config) / sizeof(pwm_config[0]); i++) {
if (pwm_config[i].port == NULL ||
(pwm_config[i].port == variant_pin_list[pin].port
&& pwm_config[i].pin_mask == variant_pin_list[pin].pin_mask)) {
@ -101,14 +101,14 @@ void analogWrite(uint8_t pin, int value) {
}
void stm32_pwm_disable(GPIO_TypeDef *port, uint32_t pin_mask) {
for(int i=0; i<sizeof(pwm_config) / sizeof(pwm_config[0]); i++) {
for(size_t i=0; i<sizeof(pwm_config) / sizeof(pwm_config[0]); i++) {
if (pwm_config[i].port == NULL) {
return;
}
if (pwm_config[i].port == port && pwm_config[i].pin_mask == pin_mask) {
for(int j = i + 1; j < sizeof(pwm_config) / sizeof(pwm_config[0]); j++) {
for(size_t j = i + 1; j < sizeof(pwm_config) / sizeof(pwm_config[0]); j++) {
if (pwm_config[j].port == NULL) {
pwm_config[i].port = pwm_config[j - 1].port;
pwm_config[i].pin_mask = pwm_config[j - 1].pin_mask;
@ -127,7 +127,7 @@ void pwm_callback() {
counter += period;
period = 256;
for(int i=0; i<sizeof(pwm_config); i++) {
for(size_t i=0; i<sizeof(pwm_config); i++) {
if (pwm_config[i].port != NULL) {
if (pwm_config[i].duty_cycle > counter % pwm_config[i].frequency) {
pwm_config[i].port->BSRR = pwm_config[i].pin_mask;

View File

@ -24,7 +24,7 @@
#include "variant.h"
void stm32GpioClock(GPIO_TypeDef *port) {
void stm32GpioClockEnable(GPIO_TypeDef *port) {
#ifdef GPIOA
if (port == GPIOA) __HAL_RCC_GPIOA_CLK_ENABLE();
@ -68,7 +68,7 @@ void pinMode(uint8_t pin, uint8_t mode) {
(*stm32_pwm_disable_callback)(port_pin.port, port_pin.pin_mask);
}
stm32GpioClock(port_pin.port);
stm32GpioClockEnable(port_pin.port);
GPIO_InitTypeDef init;

View File

@ -35,7 +35,7 @@ GPIO_TypeDef *stm32AfGetDefault(const stm32_af_pin_list_type list[], int size, c
}
uint32_t stm32GetClockFrequency(void *instance) {
for(int i=0; i<sizeof(chip_clock_freq_list) / sizeof(chip_clock_freq_list[0]); i++) {
for(size_t i=0; i<sizeof(chip_clock_freq_list) / sizeof(chip_clock_freq_list[0]); i++) {
if (chip_clock_freq_list[i].instance == instance) {
return (chip_clock_freq_list[i].clock_freq_func)();
}
@ -44,7 +44,7 @@ uint32_t stm32GetClockFrequency(void *instance) {
}
uint8_t stm32ADC1GetChannel(GPIO_TypeDef *port, uint32_t pin_mask) {
for(int i=0; i<sizeof(chip_adc1_channel) / sizeof(chip_adc1_channel[0]); i++) {
for(size_t i=0; i<sizeof(chip_adc1_channel) / sizeof(chip_adc1_channel[0]); i++) {
if (chip_adc1_channel[i].port == port && chip_adc1_channel[i].pin_mask == pin_mask) {
return chip_adc1_channel[i].channel;
}

View File

@ -44,7 +44,7 @@ void stm32AfInit(const stm32_af_pin_list_type list[], int size, const void *inst
if (port == NULL) {
port = stm32AfGetDefault(list, size, instance, &pin);
}
stm32GpioClock(port);
stm32GpioClockEnable(port);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = pin;

View File

@ -24,8 +24,6 @@
#include "stm32_gpio_af.h"
extern void stm32GpioClock(GPIO_TypeDef *port);
stm32_af_callback stm32AfGet(const stm32_af_pin_list_type list[], int size, const void *instance, const GPIO_TypeDef *port, const uint32_t pin) {
for(int i=0; i<size; i++) {
if (instance == list[i].instance
@ -45,7 +43,7 @@ void stm32AfInit(const stm32_af_pin_list_type list[], int size, const void *inst
if (port == NULL) {
port = stm32AfGetDefault(list, size, instance, &pin);
}
stm32GpioClock(port);
stm32GpioClockEnable(port);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = pin;

View File

@ -29,7 +29,7 @@ void SPIClass::begin() {
spiHandle.hdmarx = &hdma_spi_rx;
__HAL_RCC_DMA1_CLK_ENABLE();
#ifdef __HAL_RCC_DMA2_CLK_ENABLE()
#ifdef __HAL_RCC_DMA2_CLK_ENABLE
__HAL_RCC_DMA2_CLK_ENABLE();
#endif