Skip to content

Commit

Permalink
Update the pin_check related (#219)
Browse files Browse the repository at this point in the history
- enhance the logic of checking
- speed up the process
  • Loading branch information
M-ichae-l committed Feb 15, 2024
1 parent e8df712 commit 3e61f72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
60 changes: 27 additions & 33 deletions Arduino_package/hardware/cores/ambd/amb_ard_pin_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,22 @@ void amb_ard_pin_check_name(int pin) {
// TYPE_ANALOG (1UL<<21)
// TYPE_DIGITAL (1UL<<22)
void amb_ard_pin_check_type(int pin, uint32_t pin_type) {
amb_ard_pin_check_name(pin);
// char pin_type_name[] = "";
uint32_t check_bit = (g_APinDescription[pin].ulPinType & pin_type);

char pin_type_name[] = "";

switch (pin_type) {
switch (check_bit) {
case TYPE_ANALOG:
strcpy(pin_type_name, "TYPE_ANALOG");
// strcpy(pin_type_name, "TYPE_ANALOG");
break;
case TYPE_DIGITAL:
strcpy(pin_type_name, "TYPE_DIGITAL");
// strcpy(pin_type_name, "TYPE_DIGITAL");
break;
default:
printf("Error %s. Incorrect pin_type input!!! \n\r", __FUNCTION__);
}

uint32_t check_bit = (g_APinDescription[pin].ulPinType & pin_type);
while (check_bit != pin_type) {
printf("Error %s. %s is not supported by the pin: %d !!! \n\r", __FUNCTION__, pin_type_name, pin);
printf("Please check if pin or board is correct \n\r");
delay(5000);
while (1) {
printf("Error %s. Incorrect pin: %d \n\r", __FUNCTION__, pin);
printf("Please check if pin or board is correct \n\r");
delay(5000);
}
}
}

Expand All @@ -62,45 +58,43 @@ void amb_ard_pin_check_type(int pin, uint32_t pin_type) {
// PIO_UART (1UL<<8)
// PIO_SPI (1UL<<9)
void amb_ard_pin_check_fun(int pin, uint32_t pin_fun) {
char pin_fun_name[] = "";
// char pin_fun_name[] = "";
uint32_t check_bit = (g_APinDescription[pin].ulPinAttribute & pin_fun);

switch (pin_fun) {
switch (check_bit) {
case PIO_GPIO:
strcpy(pin_fun_name, "PIO_GPIO");
// strcpy(pin_fun_name, "PIO_GPIO");
break;
case PIO_PWM:
strcpy(pin_fun_name, "PIO_PWM");
// strcpy(pin_fun_name, "PIO_PWM");
break;
case PIO_I2C:
strcpy(pin_fun_name, "PIO_I2C");
// strcpy(pin_fun_name, "PIO_I2C");
break;
case PIO_ADC:
strcpy(pin_fun_name, "PIO_ADC");
// strcpy(pin_fun_name, "PIO_ADC");
break;
case PIO_DAC:
strcpy(pin_fun_name, "PIO_DAC");
// strcpy(pin_fun_name, "PIO_DAC");
break;
case PIO_GPIO_IRQ:
strcpy(pin_fun_name, "PIO_GPIO_IRQ");
// strcpy(pin_fun_name, "PIO_GPIO_IRQ");
break;
case PIO_IR:
strcpy(pin_fun_name, "PIO_IR");
// strcpy(pin_fun_name, "PIO_IR");
break;
case PIO_UART:
strcpy(pin_fun_name, "PIO_UART");
// strcpy(pin_fun_name, "PIO_UART");
break;
case PIO_SPI:
strcpy(pin_fun_name, "PIO_SPI");
// strcpy(pin_fun_name, "PIO_SPI");
break;
default:
printf("Error %s. Incorrect pin_fun input!!! \n\r", __FUNCTION__);
}

uint32_t check_bit = (g_APinDescription[pin].ulPinAttribute & pin_fun);
while (check_bit != pin_fun) {
printf("Error %s. %s is not supported by the pin: %d !!! \n\r", __FUNCTION__, pin_fun_name, pin);
printf("Please check if pin or board is correct \n\r");
delay(5000);
while (1) {
printf("Error %s. Incorrect pin: %d \n\r", __FUNCTION__, pin);
printf("Please check if pin or board is correct \n\r");
delay(5000);
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions Arduino_package/hardware/cores/ambd/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void gpioIrqHandler(uint32_t id, gpio_irq_event event) {
void pinMode(uint32_t ulPin, uint32_t ulMode) {
void *pGpio_t;

//amb_ard_pin_check_name(ulPin);
amb_ard_pin_check_type(ulPin, TYPE_DIGITAL);
// amb_ard_pin_check_name(ulPin);
// amb_ard_pin_check_type(ulPin, TYPE_DIGITAL);

if ((g_APinDescription[ulPin].ulPinMode & 0x000000FF) == ulMode) {
// Nothing changes
Expand All @@ -56,7 +56,7 @@ void pinMode(uint32_t ulPin, uint32_t ulMode) {
sys_jtag_off();
}

if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED ) == PWM_MODE_ENABLED) {
if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED) == PWM_MODE_ENABLED) {
pinRemoveMode(ulPin);
}

Expand Down Expand Up @@ -157,9 +157,9 @@ void digitalWrite(uint32_t ulPin, uint32_t ulVal) {
gpio_t *pGpio_t;

amb_ard_pin_check_type(ulPin, TYPE_DIGITAL);
amb_ard_pin_check_fun(ulPin, PIO_GPIO);
// amb_ard_pin_check_fun(ulPin, PIO_GPIO);

if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED ) == PWM_MODE_ENABLED) {
if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED) == PWM_MODE_ENABLED) {
pinMode(ulPin, (g_APinDescription[ulPin].ulPinMode));
}

Expand All @@ -172,7 +172,7 @@ int digitalRead(uint32_t ulPin) {
int pin_status;

amb_ard_pin_check_type(ulPin, TYPE_DIGITAL);
amb_ard_pin_check_fun(ulPin, PIO_GPIO);
// amb_ard_pin_check_fun(ulPin, PIO_GPIO);

if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED ) == PWM_MODE_ENABLED) {
pinMode(ulPin, (g_APinDescription[ulPin].ulPinMode));
Expand All @@ -188,7 +188,7 @@ void digitalChangeDir(uint32_t ulPin, uint8_t direction) {
//u32 RegValue;

amb_ard_pin_check_type(ulPin, TYPE_DIGITAL);
amb_ard_pin_check_fun(ulPin, PIO_GPIO);
// amb_ard_pin_check_fun(ulPin, PIO_GPIO);

if ((g_APinDescription[ulPin].ulPinMode & PWM_MODE_ENABLED ) == PWM_MODE_ENABLED) {
pinMode(ulPin, (g_APinDescription[ulPin].ulPinMode));
Expand Down

0 comments on commit 3e61f72

Please sign in to comment.