peripherial.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * peripherial.c
  3. *
  4. * Created on: Sep 10, 2024
  5. * Author: jakubski
  6. */
  7. #include "peripherial.h"
  8. void DbgLEDOn(uint8_t ledNumber)
  9. {
  10. HAL_GPIO_WritePin(GPIOD, ledNumber, GPIO_PIN_SET);
  11. }
  12. void DbgLEDOff(uint8_t ledNumber)
  13. {
  14. HAL_GPIO_WritePin(GPIOD, ledNumber, GPIO_PIN_RESET);
  15. }
  16. void DbgLEDToggle(uint8_t ledNumber)
  17. {
  18. HAL_GPIO_TogglePin(GPIOD, ledNumber);
  19. }
  20. void EnableCurrentSensors(void)
  21. {
  22. HAL_GPIO_WritePin(GPIOE, MCU_CS_PWR_EN, GPIO_PIN_SET);
  23. }
  24. void DisableCurrentSensors(void)
  25. {
  26. HAL_GPIO_WritePin(GPIOE, MCU_CS_PWR_EN, GPIO_PIN_RESET);
  27. }
  28. void SelectCurrentSensorGain(CurrentSensor sensor, CurrentSensorGain gain)
  29. {
  30. uint8_t gpioOffset = 0;
  31. switch(sensor)
  32. {
  33. case CurrentSensorL1:
  34. gpioOffset = CURRENT_SENSOR_L1_GPIO_OFFSET;
  35. break;
  36. case CurrentSensorL2:
  37. gpioOffset = CURRENT_SENSOR_L2_GPIO_OFFSET;
  38. break;
  39. case CurrentSensorL3:
  40. gpioOffset = CURRENT_SENSOR_L3_GPIO_OFFSET;
  41. break;
  42. default:
  43. break;
  44. }
  45. if(gpioOffset > 0)
  46. {
  47. uint16_t gain0Gpio = 1 << gpioOffset;
  48. uint16_t gain1Gpio = 1 << (gpioOffset + 1);
  49. uint16_t gpioState = ((uint16_t)gain) & 0x0001;
  50. HAL_GPIO_WritePin(GPIOE, gain0Gpio, gpioState);
  51. gpioState = (((uint16_t)gain) >> 1) & 0x0001;
  52. HAL_GPIO_WritePin(GPIOE, gain1Gpio, gpioState);
  53. }
  54. }