You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

111 lines
1.8 KiB

#include "chip.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
uint8_t g_port_exit_critical_count;
// NVIC_EnableIRQ
// NVIC_GetEnableIRQ
// NVIC_DisableIRQ
void chip_critical_enter(void) {
if (g_port_exit_critical_count == 0) {
__disable_irq();
// NVIC_DisableIRQ();
}
g_port_exit_critical_count++;
}
void chip_critical_exit(void) {
g_port_exit_critical_count--;
if (g_port_exit_critical_count == 0) {
// NVIC_EnableIRQ();
__enable_irq();
}
}
GPIO_TypeDef* chip_get_gpio(Pin_t pin) {
int port = pin >> 4;
switch (port) {
case 1:
#ifdef GPIOA
return GPIOA;
#endif
break;
case 2:
#ifdef GPIOB
return GPIOB;
#endif
break;
case 3:
#ifdef GPIOC
return GPIOC;
#endif
break;
case 4:
#ifdef GPIOD
return GPIOD;
#endif
break;
case 5:
#ifdef GPIOE
return GPIOE;
#endif
break;
case 6:
#ifdef GPIOF
return GPIOF;
#endif
break;
case 7:
#ifdef GPIOG
return GPIOG;
#endif
break;
default:
break;
}
return NULL;
}
uint16_t chip_get_pinoff(Pin_t pin) {
uint16_t pinoff = pin & 0x0F;
switch (pinoff) {
case 0:
return GPIO_PIN_0;
case 1:
return GPIO_PIN_1;
case 2:
return GPIO_PIN_2;
case 3:
return GPIO_PIN_3;
case 4:
return GPIO_PIN_4;
case 5:
return GPIO_PIN_5;
case 6:
return GPIO_PIN_6;
case 7:
return GPIO_PIN_7;
case 8:
return GPIO_PIN_8;
case 9:
return GPIO_PIN_9;
case 10:
return GPIO_PIN_10;
case 11:
return GPIO_PIN_11;
case 12:
return GPIO_PIN_12;
case 13:
return GPIO_PIN_13;
case 14:
return GPIO_PIN_14;
case 15:
return GPIO_PIN_15;
default:
break;
};
return 0;
}