Skip to content

Commit

Permalink
fix(AT32F421/Core): remove invalid definition
Browse files Browse the repository at this point in the history
  • Loading branch information
FASTSHIFT committed Sep 4, 2022
1 parent fcdb246 commit 24954c5
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 183 deletions.
46 changes: 24 additions & 22 deletions _Keilduino/ArduinoAPI/Arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,29 @@ void pinMode(uint8_t pin, PinMode_TypeDef mode)
return;
}

if(mode == INPUT_ANALOG_DMA)
switch(mode)
{
case INPUT_ANALOG_DMA:
if(!IS_ADC_PIN(pin))
{
return;
}

pinMode(pin, INPUT_ANALOG);
ADC_DMA_Register(PIN_MAP[pin].ADC_Channel);
}
else if(mode == PWM)
{
break;

case PWM:
PWM_Init(pin, PWM_RESOLUTION_DEFAULT, PWM_FREQUENCY_DEFAULT);
}
else
{
break;

default:
GPIOx_Init(
PIN_MAP[pin].GPIOx,
PIN_MAP[pin].GPIO_Pin_x,
mode,
GPIO_DRIVE_DEFAULT
);
break;
}
}

Expand Down Expand Up @@ -147,7 +148,7 @@ uint16_t analogRead_DMA(uint8_t pin)
*/
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
{
uint8_t i;
int i;
if(!(IS_PIN(dataPin) && IS_PIN(clockPin)))
{
return;
Expand All @@ -173,7 +174,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value
uint32_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint32_t bitOrder)
{
uint8_t value = 0;
uint8_t i;
int i;

if(!(IS_PIN(dataPin) && IS_PIN(clockPin)))
{
Expand Down Expand Up @@ -206,26 +207,27 @@ uint32_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint32_t bitOrder)
*/
uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
{
// cache the IDR address and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.

/** cache the IDR address and bit of the pin in order to speed up the
* pulse width measuring loop and achieve finer resolution. calling
* digitalRead() instead yields much coarser resolution.
*/
volatile uint32_t *idr = portInputRegister(digitalPinToPort(pin));
const uint32_t bit = digitalPinToBitMask(pin);
const uint32_t stateMask = (state ? bit : 0);

uint32_t width = 0; // keep initialization out of time critical area

// convert the timeout from microseconds to a number of times through
// the initial loop; it takes 16 clock cycles per iteration.
/** convert the timeout from microseconds to a number of times through
* the initial loop; it takes 16 clock cycles per iteration.
*/
uint32_t numloops = 0;
uint32_t maxloops = timeout * ( F_CPU / 16000000);
volatile uint32_t dummyWidth = 0;

if(!IS_PIN(pin))
return 0;

// wait for any previous pulse to end
/* wait for any previous pulse to end */
while ((*idr & bit) == stateMask)
{
if (numloops++ == maxloops)
Expand All @@ -235,7 +237,7 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
dummyWidth++;
}

// wait for the pulse to start
/* wait for the pulse to start */
while ((*idr & bit) != stateMask)
{
if (numloops++ == maxloops)
Expand All @@ -245,7 +247,7 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
dummyWidth++;
}

// wait for the pulse to stop
/* wait for the pulse to stop */
while ((*idr & bit) == stateMask)
{
if (numloops++ == maxloops)
Expand All @@ -255,9 +257,9 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
width++;
}

// Excluding time taking up by the interrupts, it needs 16 clock cycles to look through the last while loop
// 5 is added as a fiddle factor to correct for interrupts etc. But ultimately this would only be accurate if it was done ona hardware timer

/** Excluding time taking up by the interrupts, it needs 16 clock cycles to look through the last while loop
* 5 is added as a fiddle factor to correct for interrupts etc. But ultimately this would only be accurate if it was done ona hardware timer
*/
return (uint32_t)( ( (unsigned long long)(width + 5) * (unsigned long long) 16000000.0) / (unsigned long long)F_CPU );
}

Expand Down
13 changes: 1 addition & 12 deletions _Keilduino/Platform/AT32F421/Config/mcu_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,12 @@
# define SERIAL_1_IRQ_HANDLER_DEF() void USART1_IRQHandler(void)
#endif

#define SERIAL_2_ENABLE 0
#define SERIAL_2_ENABLE 1
#if SERIAL_2_ENABLE
# define SERIAL_2_USART USART2
# define SERIAL_2_IRQ_HANDLER_DEF() void USART2_IRQHandler(void)
#endif

#define SERIAL_3_ENABLE 0
#if SERIAL_3_ENABLE
# define SERIAL_3_USART USART3
# define SERIAL_3_IRQ_HANDLER_DEF() void USART3_IRQHandler(void)
#endif

/* Wire (Software I2C) */
#define WIRE_USE_FULL_SPEED_I2C 0
#define WIRE_SDA_PIN PB7
Expand All @@ -77,11 +71,6 @@
# define SPI_CLASS_2_SPI SPI2
#endif

#define SPI_CLASS_3_ENABLE 1
#if SPI_CLASS_3_ENABLE
# define SPI_CLASS_3_SPI SPI3
#endif

/* WString */
#define WSTRING_MEM_INCLUDE <stdlib.h>
#define WSTRING_MEM_REALLOC realloc
Expand Down
1 change: 0 additions & 1 deletion _Keilduino/Platform/AT32F421/Core/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#define SPI1_CLOCK (F_CPU)
#define SPI2_CLOCK (F_CPU)
#define SPI3_CLOCK (F_CPU)

SPIClass::SPIClass(spi_type* spix)
: SPIx(spix)
Expand Down
72 changes: 13 additions & 59 deletions _Keilduino/Platform/AT32F421/Core/exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static EXTI_CallbackFunction_t EXTI_Function[16] = {0};
*/
static IRQn_Type EXTI_GetIRQn(uint8_t Pin)
{
IRQn_Type EXINTx_IRQn = EXINT1_0_IRQn;
IRQn_Type EXINTx_IRQn;
uint8_t Pinx = GPIO_GetPinNum(Pin);

if(Pinx <= 1)
Expand All @@ -46,7 +46,7 @@ static IRQn_Type EXTI_GetIRQn(uint8_t Pin)
{
EXINTx_IRQn = EXINT3_2_IRQn;
}
else if(Pinx >= 4 && Pinx <= 15)
else
{
EXINTx_IRQn = EXINT15_4_IRQn;
}
Expand Down Expand Up @@ -128,86 +128,40 @@ void detachInterrupt(uint8_t Pin)
nvic_irq_disable(EXTI_GetIRQn(Pin));
}

#define EXTIx_IRQHANDLER(n) \
do{\
if(exint_flag_get(EXINT_LINE_##n) != RESET)\
{\
if(EXTI_Function[n]) EXTI_Function[n]();\
exint_flag_clear(EXINT_LINE_##n);\
}\
#define EXTIx_IRQHANDLER(n) \
do{ \
if(exint_flag_get(EXINT_LINE_##n) != RESET) \
{ \
if(EXTI_Function[n]) EXTI_Function[n](); \
exint_flag_clear(EXINT_LINE_##n); \
} \
}while(0)

/**
* @brief 外部中断入口,通道0
* @brief 外部中断入口
* @param 无
* @retval 无
*/
void EXINT0_IRQHandler(void)
void EXINT1_0_IRQHandler(void)
{
EXTIx_IRQHANDLER(0);
}

/**
* @brief 外部中断入口,通道1
* @param 无
* @retval 无
*/
void EXINT1_IRQHandler(void)
{
EXTIx_IRQHANDLER(1);
}

/**
* @brief 外部中断入口,通道2
* @param 无
* @retval 无
*/
void EXINT2_IRQHandler(void)
void EXINT3_2_IRQHandler(void)
{
EXTIx_IRQHANDLER(2);
}

/**
* @brief 外部中断入口,通道3
* @param 无
* @retval 无
*/
void EXINT3_IRQHandler(void)
{
EXTIx_IRQHANDLER(3);
}

/**
* @brief 外部中断入口,通道4
* @param 无
* @retval 无
*/
void EXINT4_IRQHandler(void)
void EXINT15_4_IRQHandler(void)
{
EXTIx_IRQHANDLER(4);
}

/**
* @brief 外部中断入口,通道9~5
* @param 无
* @retval 无
*/
void EXINT9_5_IRQHandler(void)
{
EXTIx_IRQHANDLER(5);
EXTIx_IRQHANDLER(6);
EXTIx_IRQHANDLER(7);
EXTIx_IRQHANDLER(8);
EXTIx_IRQHANDLER(9);
}

/**
* @brief 外部中断入口,通道15~10
* @param 无
* @retval 无
*/
void EXINT15_10_IRQHandler(void)
{
EXTIx_IRQHANDLER(10);
EXTIx_IRQHANDLER(11);
EXTIx_IRQHANDLER(12);
Expand Down
Loading

0 comments on commit 24954c5

Please sign in to comment.