добавлена поддержка платы Start-MIK32
This commit is contained in:
1 parent
8c82685f37
commit
f06650400b
46 files changed
+1813
-163
No files matched your search
+12
-12
@@ -27,24 +27,24 @@ void noInterrupts(void)
|
||||
}
|
||||
|
||||
// we can provide no more than 8 interrupts on gpio at the same time
|
||||
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] =
|
||||
static volatile voidFuncPtr intFunc[EXTERNAL_INTERRUPTS_QTY] =
|
||||
{
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 7
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 7
|
||||
nothing,
|
||||
#endif
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 6
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 6
|
||||
nothing,
|
||||
#endif
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 5
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 5
|
||||
nothing,
|
||||
#endif
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 4
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 4
|
||||
nothing,
|
||||
#endif
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 3
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 3
|
||||
nothing,
|
||||
#endif
|
||||
#if EXTERNAL_NUM_INTERRUPTS > 2
|
||||
#if EXTERNAL_INTERRUPTS_QTY > 2
|
||||
nothing,
|
||||
#endif
|
||||
nothing,
|
||||
@@ -54,7 +54,7 @@ static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] =
|
||||
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
|
||||
{
|
||||
// if the interrupt number does not exceed the total number
|
||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
|
||||
{
|
||||
intFunc[interruptNum] = userFunc; // save pointer to irq handler
|
||||
|
||||
@@ -85,7 +85,7 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
|
||||
|
||||
void detachInterrupt(uint8_t interruptNum)
|
||||
{
|
||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
|
||||
{
|
||||
// disable the interrupt in line
|
||||
HAL_GPIO_DeInitInterruptLine(interruptToGpioIntLine(interruptNum));
|
||||
@@ -98,7 +98,7 @@ void detachInterrupt(uint8_t interruptNum)
|
||||
// disable single interrupt
|
||||
void disableInterrupt(uint8_t interruptNum)
|
||||
{
|
||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
|
||||
// disable gpio interrupt line
|
||||
GPIO_IRQ_LINE_DISABLE(interruptToGpioIntLine(interruptNum));
|
||||
}
|
||||
@@ -106,7 +106,7 @@ void disableInterrupt(uint8_t interruptNum)
|
||||
// enable single interrupt
|
||||
void enableInterrupt(uint8_t interruptNum)
|
||||
{
|
||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
|
||||
// enable gpio interrupt line
|
||||
GPIO_IRQ_LINE_ENABLE(interruptToGpioIntLine(interruptNum));
|
||||
}
|
||||
@@ -115,7 +115,7 @@ void enableInterrupt(uint8_t interruptNum)
|
||||
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) gpio_interrupt_handler(void)
|
||||
{
|
||||
// go through all the interrupts and call the handler for the triggered line
|
||||
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||
for (uint8_t i = 0; i < EXTERNAL_INTERRUPTS_QTY; i++)
|
||||
{
|
||||
if (GPIO_IRQ_LINE_STATE(interruptToGpioIntLine(i)))
|
||||
intFunc[i]();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "mik32_hal_irq.h"
|
||||
#include "wiring_LL.h"
|
||||
#include "mik32_hal_irq.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
// isr functions
|
||||
extern void serial_interrupt_handler(uint8_t uartNumInt);
|
||||
@@ -11,12 +11,37 @@ void __attribute__((weak)) wire_interrupt_handler(void)
|
||||
}
|
||||
void __attribute__((weak)) servo_interrupt_handler(void)
|
||||
{
|
||||
// dummy function for case when wire library is not in use
|
||||
// dummy function for case when servo library is not in use
|
||||
}
|
||||
|
||||
void __attribute__((weak)) ISR(void)
|
||||
{
|
||||
/*
|
||||
A dummy function for the case when additional interrupts are not used in the project.
|
||||
In the project, you need to create a function of the form:
|
||||
extern "C" void ISR()
|
||||
{
|
||||
// timer16 is taken as an example
|
||||
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
|
||||
{
|
||||
// necessary actions
|
||||
}
|
||||
// reset timer interrupt flags
|
||||
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
|
||||
}
|
||||
libraries required to use this example:
|
||||
#include "mik32_hal_timer16.h"
|
||||
#include "mik32_hal_irq.h"
|
||||
#include "wiring_LL.h"
|
||||
*/
|
||||
}
|
||||
|
||||
// ---------------------------------------------- //
|
||||
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handler (void)
|
||||
{
|
||||
// custom interrupt
|
||||
ISR();
|
||||
|
||||
// gpio interrupt
|
||||
if (EPIC_CHECK_GPIO_IRQ())
|
||||
gpio_interrupt_handler();
|
||||
@@ -36,7 +61,7 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
|
||||
// uart1 interrupt
|
||||
if (EPIC_CHECK_UART_1())
|
||||
serial_interrupt_handler(1);
|
||||
|
||||
|
||||
// i2c interrupt
|
||||
if (EPIC_CHECK_I2C_1())
|
||||
wire_interrupt_handler();
|
||||
|
||||
@@ -42,18 +42,8 @@ uint32_t analogRead(uint32_t PinNumber)
|
||||
uint32_t adcChannel = analogInputToChannelNumber(PinNumber);
|
||||
if (adcChannel != NC)
|
||||
{
|
||||
// if we use pin A5, we need to set SELA45 (1.15) to 1 to switch the output from A4 to A5
|
||||
if (PinNumber == A5)
|
||||
{
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_HIGH);
|
||||
}
|
||||
else if(PinNumber == A4)
|
||||
{
|
||||
// return the switch to A4 in case A5 was previously read
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_LOW);
|
||||
}
|
||||
additionalPinsInit(PinNumber);
|
||||
|
||||
// init channel
|
||||
hadc.Init.Sel = adcChannel;
|
||||
HAL_ADC_Init(&hadc);
|
||||
@@ -147,8 +137,6 @@ void analogWrite(uint32_t PinNumber, uint32_t writeVal)
|
||||
HAL_Timer32_Start(&htimer32);
|
||||
pwmIsInited++; // increase inited channels qty
|
||||
}
|
||||
else if(PinNumber == 10) // pin d10 has pwm, but you cannot use it while spi is running
|
||||
ErrorMsgHandler("analogWrite(): D10 cannot be used as PWM pin while SPI is running");
|
||||
else
|
||||
ErrorMsgHandler("analogWrite(): invalid pwm pin number");
|
||||
}
|
||||
|
||||
@@ -40,59 +40,30 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
// adjusting pins
|
||||
if (PinNumber == BTN_BUILTIN)
|
||||
// determine the port and the pin number in the port
|
||||
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
|
||||
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
|
||||
|
||||
// set up direction and pull up/down
|
||||
switch (PinMode)
|
||||
{
|
||||
// always set the button to input, otherwise the controller may burn out when pressed
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
HAL_GPIO_Init(GPIO_2, &GPIO_InitStruct);
|
||||
}
|
||||
else // other pins
|
||||
{
|
||||
// determine the port and the pin number in the port
|
||||
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
|
||||
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
|
||||
|
||||
// set up direction and pull up/down
|
||||
switch (PinMode)
|
||||
{
|
||||
case INPUT:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
break;
|
||||
case INPUT_PULLUP:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
|
||||
break;
|
||||
case OUTPUT:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
// init pin
|
||||
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
|
||||
|
||||
// if we use pin A5, we need to set SELA45 (1.15) to 1 to switch the output from A4 to A5
|
||||
if (PinNumber == A5)
|
||||
{
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_15;
|
||||
case INPUT:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
break;
|
||||
case INPUT_PULLUP:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
|
||||
break;
|
||||
case OUTPUT:
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
HAL_GPIO_Init(GPIO_1, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_HIGH);
|
||||
}
|
||||
else if(PinNumber == A4)
|
||||
{
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
|
||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||
HAL_GPIO_Init(GPIO_1, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_LOW);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// init pin
|
||||
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
|
||||
additionalPinsInit(PinNumber);
|
||||
}
|
||||
|
||||
// write pin
|
||||
@@ -108,11 +79,7 @@ void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
// just in case let's move on to the hal library state terms
|
||||
GPIO_PinState pinState = (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
|
||||
|
||||
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
|
||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), pinState);
|
||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
|
||||
}
|
||||
|
||||
// read pin
|
||||
@@ -128,8 +95,7 @@ int digitalRead(uint32_t PinNumber)
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
int state = (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||
return state;
|
||||
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||
}
|
||||
|
||||
// toggle pin
|
||||
@@ -144,8 +110,7 @@ void digitalToggle(uint32_t PinNumber)
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
|
||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -11,7 +11,7 @@ extern "C"{
|
||||
#endif
|
||||
|
||||
// available interrupts number
|
||||
#define EXTERNAL_NUM_INTERRUPTS 7
|
||||
#define EXTERNAL_NUM_INTERRUPTS EXTERNAL_INTERRUPTS_QTY
|
||||
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user