Statistics
| Branch: | Tag: | Revision:

amiro-os / boards / LightRing / board.c @ 58fe0e0b

History | View | Annotate | Download (1.96 KB)

1 58fe0e0b Thomas Schöpping
#include "ch.h"
2
#include "hal.h"
3
4
/**
5
 * @brief   PAL setup.
6
 * @details Digital I/O ports static configuration as defined in @p board.h.
7
 *          This variable is used by the HAL when initializing the PAL driver.
8
 */
9
#if HAL_USE_PAL || defined(__DOXYGEN__)
10
const PALConfig pal_default_config =
11
{
12
  {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
13
  {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
14
  {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
15
  {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
16
  {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
17
  {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH},
18
  {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH},
19
};
20
21
#endif
22
23
/*
24
 * Early initialization code.
25
 * This initialization must be performed just after stack setup and before
26
 * any other initialization.
27
 */
28
void __early_init(void) {
29
30
  stm32_clock_init();
31
}
32
33
/*
34
 * Board-specific initialization code.
35
 */
36
void boardInit(void) {
37
  /*
38
   * Several I/O pins are re-mapped:
39
   *   JTAG disabled and SWD enabled
40
   */
41
  AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE |
42
               AFIO_MAPR_USART3_REMAP_PARTIALREMAP;
43
}
44
45
inline void boardRequestShutdown(void)
46
{
47
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
48
}
49
50
inline void boardStandby(void)
51
{
52
53
  palSetPad(GPIOC, GPIOC_SYS_PD_N);
54
  chSysLock();
55
  // Standby
56
  // set deepsleep bit
57
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
58
  // set PDDS, clear WUF, clear SBF
59
  PWR->CR |= (PWR_CR_CWUF | PWR_CR_PDDS | PWR_CR_CSBF);
60
  // clear RTC wakeup source flags
61
  RTC->CRL &= ~(RTC_CRL_ALRF);
62
  // Wait for Interrupt
63
  __WFI();
64
65
}
66
67
inline void boardClearI2CBus(const uint8_t scl_pad) {
68
69
  uint8_t i;
70
71
  // configure I²C SCL open drain
72
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN);
73
74
  // perform bus clear as per I²C Specification v5 3.1.16
75
  for (i = 0x00u; i < 0x09u; i++) {
76
    palClearPad(GPIOB, scl_pad);
77
    chThdSleepMicroseconds(5);
78
    palSetPad(GPIOB, scl_pad);
79
    chThdSleepMicroseconds(5);
80
  }
81
82
  // reconfigure I²C SCL
83
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
84
85
}