xa_shield.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "stm32l0xx_hal.h"
  2. #include "xa_shield.h"
  3. #include "x-nucleo-6180xa1.h"
  4. #include <stdio.h>
  5. #include <stdio.h>
  6. I2C_HandleTypeDef i2_handle;
  7. volatile uint32_t tick_cnt;
  8. static void wait_ms(int ms);
  9. // PB8, PB9 - I2C_1
  10. // Inputs GPIO_MODE_IT_RISING : PA4 = INTB , PA5 = INTL, PA10 = INTR, PB0 = INT
  11. void xa_shield(void)
  12. {
  13. XNUCLEO6180XA1_GPIO_Init();
  14. XNUCLEO6180XA1_I2C1_Init(&i2_handle);
  15. }
  16. //
  17. extern "C" {
  18. void HAL_SYSTICK_Callback(void)
  19. {
  20. tick_cnt++;
  21. }
  22. }
  23. //
  24. void wait_ms(int ms)
  25. {
  26. uint32_t start, now;
  27. int dif;
  28. start = tick_cnt;
  29. do {
  30. now = tick_cnt;
  31. dif = now - start;
  32. }
  33. while (dif < ms);
  34. }
  35. // Нужно определить функцию задержки из x-nucleo-6180xa1
  36. void XNUCLEO6180XA1_WaitMilliSec(int SegDelayMs)
  37. {
  38. //wait_ms(SegDelayMs);
  39. HAL_Delay(SegDelayMs);
  40. }
  41. //
  42. void xa_shield_test(void)
  43. {
  44. char str[6] = {"Err_"};
  45. //static uint8_t cnt = 0;
  46. //
  47. //int ret = XNUCLEO6180XA1_GetSwitch();
  48. //printf("Switch state: %u\r\n", ret);
  49. //sprintf(str, "%u", cnt);
  50. XNUCLEO6180XA1_DisplayString(str, 1);
  51. //HAL_Delay(1000);
  52. }