dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_board.c
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 /* Pull in the board-specific static HW definitions.
32  * Including .c files is a bit ugly but this allows all of
33  * the HW definitions to be const and static to limit their
34  * scope.
35  *
36  * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE
37  */
38 #include "board_hw_defs.c"
39 
40 #include <pios_board_info.h>
41 #include <pios.h>
42 
44 
46 {
47  const struct pios_servo_cfg * servo_cfg = &pios_servo_cfg;
48  const struct pios_tim_channel * channels = servo_cfg->channels;
49  uint8_t num_channels = servo_cfg->num_channels;
50  for (int i = 0; i < num_channels; i++) {
51  GPIO_InitTypeDef init = {
52  .GPIO_Pin = channels[i].pin.init.GPIO_Pin,
53  .GPIO_Speed = GPIO_Speed_2MHz,
54  .GPIO_Mode = GPIO_Mode_OUT,
55  .GPIO_OType = GPIO_OType_PP,
56  .GPIO_PuPd = GPIO_PuPd_DOWN
57  };
58 
59  /* Nail all servo channels as outputs, LOW.
60  * Mostly for brushed clones of SPRF3E to ensure we don't
61  * spin up (they should provide pulldowns, but meh.)
62  */
63  channels[i].pin.gpio->BSRR = channels[i].pin.init.GPIO_Pin << 16;
64  GPIO_Init(channels[i].pin.gpio, &init);
65  channels[i].pin.gpio->BSRR = channels[i].pin.init.GPIO_Pin << 16;
66  }
67 
68  /* Delay system */
70 
71 #if defined(PIOS_INCLUDE_ANNUNC)
73 #endif /* PIOS_INCLUDE_ANNUNC */
74 
75 #if defined(PIOS_INCLUDE_FLASH)
76  /* Inititialize all flash drivers */
77  PIOS_Flash_Internal_Init(&pios_internal_flash_id, &flash_internal_cfg);
78 
79  /* Register the partition table */
81 #endif /* PIOS_INCLUDE_FLASH */
82 
83 #if defined(PIOS_INCLUDE_USB)
84  /* Initialize board specific USB data */
86 
87  /* Activate the HID-only USB configuration */
89 
90  uintptr_t pios_usb_id;
91  PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
92 
93 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM_MSG)
94  uintptr_t pios_usb_hid_id;
95  if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
96  PIOS_Assert(0);
97  }
99  PIOS_Assert(0);
100  }
101 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM_MSG */
102 
103 #endif /* PIOS_INCLUDE_USB */
104 }
105 
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
Main PiOS header to include all the compiled in PiOS options.
GPIO_InitTypeDef init
Definition: pios_stm32.h:61
#define NELEMENTS(x)
Definition: pios.h:192
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
int32_t PIOS_USB_HID_Init(uintptr_t *usbhid_id, const struct pios_usb_hid_cfg *cfg, uintptr_t lower_id)
const struct pios_tim_channel * channels
struct stm32_gpio pin
Definition: pios_tim_priv.h:17
int32_t PIOS_DELAY_Init(void)
Definition: pios_delay.c:98
const struct pios_com_driver pios_usb_hid_com_driver
void PIOS_Board_Init()
Definition: pios_board.c:44
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
uint8_t i
Definition: msp_messages.h:97
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
const struct pios_servo_cfg pios_servo_cfg
Sparky2 has all 10 outputs.
uintptr_t pios_com_telem_usb_id
Definition: pios_board.c:42
int32_t PIOS_COM_MSG_Init(uintptr_t *com_id, const struct pios_com_driver *driver, uintptr_t lower_id)
void PIOS_FLASH_register_partition_table(const struct pios_flash_partition partition_table[], uint8_t num_partitions)
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
uint8_t num_channels
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
#define PIOS_Assert(test)
Definition: pios_debug.h:52
int32_t PIOS_USB_BOARD_DATA_Init(void)
static const struct pios_servo_cfg * servo_cfg
Definition: pios_servo.c:55