37 #include "board_hw_defs.c"
42 #include <uavobjectsinit.h>
43 #include "hwsparky2.h"
44 #include "manualcontrolsettings.h"
45 #include "modulesettings.h"
49 #define PIOS_COM_CAN_RX_BUF_LEN 256
50 #define PIOS_COM_CAN_TX_BUF_LEN 256
65 case HWSPARKY2_VTX_CH_BOSCAMACH15725:
68 case HWSPARKY2_VTX_CH_BOSCAMACH25745:
72 case HWSPARKY2_VTX_CH_BOSCAMACH35765:
76 case HWSPARKY2_VTX_CH_BOSCAMACH45785:
80 case HWSPARKY2_VTX_CH_BOSCAMACH55805:
84 case HWSPARKY2_VTX_CH_BOSCAMACH65825:
88 case HWSPARKY2_VTX_CH_BOSCAMACH75845:
92 case HWSPARKY2_VTX_CH_BOSCAMACH85865:
96 case HWSPARKY2_VTX_CH_BOSCAMBCH15733:
100 case HWSPARKY2_VTX_CH_BOSCAMBCH25752:
104 case HWSPARKY2_VTX_CH_BOSCAMBCH35771:
108 case HWSPARKY2_VTX_CH_BOSCAMBCH45790:
112 case HWSPARKY2_VTX_CH_BOSCAMBCH55809:
116 case HWSPARKY2_VTX_CH_BOSCAMBCH65828:
120 case HWSPARKY2_VTX_CH_BOSCAMBCH75847:
124 case HWSPARKY2_VTX_CH_BOSCAMBCH85866:
128 case HWSPARKY2_VTX_CH_BOSCAMECH15705:
132 case HWSPARKY2_VTX_CH_BOSCAMECH25685:
136 case HWSPARKY2_VTX_CH_BOSCAMECH35665:
140 case HWSPARKY2_VTX_CH_BOSCAMECH45645:
144 case HWSPARKY2_VTX_CH_BOSCAMECH55885:
148 case HWSPARKY2_VTX_CH_BOSCAMECH65905:
152 case HWSPARKY2_VTX_CH_BOSCAMECH75925:
156 case HWSPARKY2_VTX_CH_BOSCAMECH85945:
160 case HWSPARKY2_VTX_CH_AIRWAVECH15740:
164 case HWSPARKY2_VTX_CH_AIRWAVECH25760:
168 case HWSPARKY2_VTX_CH_AIRWAVECH35780:
172 case HWSPARKY2_VTX_CH_AIRWAVECH45800:
176 case HWSPARKY2_VTX_CH_AIRWAVECH55820:
180 case HWSPARKY2_VTX_CH_AIRWAVECH65840:
184 case HWSPARKY2_VTX_CH_AIRWAVECH75860:
188 case HWSPARKY2_VTX_CH_AIRWAVECH85860:
194 GPIO_InitTypeDef GPIO_InitStructure;
195 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
196 GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
197 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
198 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
200 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
201 GPIO_Init(GPIOB, &GPIO_InitStructure);
202 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
203 GPIO_Init(GPIOB, &GPIO_InitStructure);
204 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
205 GPIO_Init(GPIOB, &GPIO_InitStructure);
208 GPIO_SetBits(GPIOB, GPIO_Pin_14);
210 GPIO_ResetBits(GPIOB, GPIO_Pin_14);
214 GPIO_SetBits(GPIOB, GPIO_Pin_13);
216 GPIO_ResetBits(GPIOB, GPIO_Pin_13);
220 GPIO_SetBits(GPIOB, GPIO_Pin_12);
222 GPIO_ResetBits(GPIOB, GPIO_Pin_12);
225 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
226 GPIO_Init(GPIOA, &GPIO_InitStructure);
227 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
228 GPIO_Init(GPIOA, &GPIO_InitStructure);
231 GPIO_SetBits(GPIOA, GPIO_Pin_9);
233 GPIO_ResetBits(GPIOA, GPIO_Pin_9);
237 GPIO_SetBits(GPIOA, GPIO_Pin_10);
239 GPIO_ResetBits(GPIOA, GPIO_Pin_10);
258 for (
int i = 0;
i < num_channels;
i++) {
259 GPIO_Init(channels[
i].
pin.
gpio, (GPIO_InitTypeDef*) &channels[i].
pin.
init);
262 #if defined(PIOS_INCLUDE_ANNUNC)
276 if (
PIOS_SPI_Init(&pios_spi_telem_flash_id, &pios_spi_telem_flash_cfg)) {
280 #if defined(PIOS_INCLUDE_FLASH)
282 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
283 if (get_external_flash(bdinfo->
board_rev)) {
284 if (
PIOS_Flash_Jedec_Init(&pios_external_flash_id, pios_spi_telem_flash_id, 1, &flash_m25p_cfg) != 0)
293 uint32_t num_partitions;
294 flash_partition_table = PIOS_BOARD_HW_DEFS_GetPartitionTable(bdinfo->
board_rev, &num_partitions);
300 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
306 HwSparky2Initialize();
307 ModuleSettingsInitialize();
309 #if defined(PIOS_INCLUDE_RTC)
316 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
329 NVIC_InitTypeDef tim_8_up_irq = {
330 .NVIC_IRQChannel = TIM8_UP_TIM13_IRQn,
332 .NVIC_IRQChannelSubPriority = 0,
333 .NVIC_IRQChannelCmd = ENABLE,
335 NVIC_Init(&tim_8_up_irq);
340 if (boot_count < 3) {
345 HwSparky2SetDefaults(HwSparky2Handle(), 0);
346 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
347 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
353 #if defined(PIOS_INCLUDE_USB)
358 bool usb_hid_present =
false;
359 bool usb_cdc_present =
false;
361 #if defined(PIOS_INCLUDE_USB_CDC)
365 usb_hid_present =
true;
366 usb_cdc_present =
true;
371 usb_hid_present =
true;
374 uintptr_t pios_usb_id;
377 #if defined(PIOS_INCLUDE_USB_CDC)
379 uint8_t hw_usb_vcpport;
381 HwSparky2USB_VCPPortGet(&hw_usb_vcpport);
383 if (!usb_cdc_present) {
385 hw_usb_vcpport = HWSPARKY2_USB_VCPPORT_DISABLED;
392 #if defined(PIOS_INCLUDE_USB_HID)
394 uint8_t hw_usb_hidport;
395 HwSparky2USB_HIDPortGet(&hw_usb_hidport);
397 if (!usb_hid_present) {
399 hw_usb_hidport = HWSPARKY2_USB_HIDPORT_DISABLED;
406 if (usb_hid_present || usb_cdc_present) {
412 HwSparky2DSMxModeOptions hw_DSMxMode;
413 HwSparky2DSMxModeGet(&hw_DSMxMode);
417 HwSparky2MainPortGet(&hw_mainport);
419 PIOS_HAL_ConfigurePort(hw_mainport,
432 uint8_t hw_flexiport;
433 HwSparky2FlexiPortGet(&hw_flexiport);
435 PIOS_HAL_ConfigurePort(hw_flexiport,
438 &pios_i2c_flexiport_adapter_id,
439 &pios_i2c_flexiport_adapter_cfg,
447 #if defined(PIOS_INCLUDE_OPENLRS)
448 HwSparky2Data hwSparky2;
449 HwSparky2Get(&hwSparky2);
451 const struct pios_openlrs_cfg *openlrs_cfg = PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(bdinfo->
board_rev);
453 PIOS_HAL_ConfigureRFM22B(pios_spi_telem_flash_id,
455 hwSparky2.RfBand, hwSparky2.MaxRfPower,
456 openlrs_cfg, &openlrs_handle);
461 HwSparky2RcvrPortGet(&hw_rcvrport);
464 hw_DSMxMode = HWSPARKY2_DSMXMODE_AUTODETECT;
467 PIOS_HAL_ConfigurePort(hw_rcvrport,
479 #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
486 if (
PIOS_I2C_Init(&pios_i2c_mag_pressure_adapter_id, &pios_i2c_mag_pressure_adapter_cfg)) {
490 #if defined(PIOS_INCLUDE_CAN)
508 #if defined(PIOS_INCLUDE_ADC)
509 uintptr_t internal_adc_id;
514 #if defined(PIOS_INCLUDE_MS5611)
516 || (PIOS_MS5611_Test() != 0))
520 uint8_t Magnetometer;
521 HwSparky2MagnetometerGet(&Magnetometer);
523 if (Magnetometer != HWSPARKY2_MAGNETOMETER_INTERNAL)
527 #if defined(PIOS_INCLUDE_MPU)
532 HwSparky2GyroRangeOptions hw_gyro_range;
533 HwSparky2GyroRangeGet(&hw_gyro_range);
534 switch(hw_gyro_range) {
535 case HWSPARKY2_GYRORANGE_250:
538 case HWSPARKY2_GYRORANGE_500:
541 case HWSPARKY2_GYRORANGE_1000:
544 case HWSPARKY2_GYRORANGE_2000:
549 HwSparky2AccelRangeOptions hw_accel_range;
550 HwSparky2AccelRangeGet(&hw_accel_range);
551 switch(hw_accel_range) {
552 case HWSPARKY2_ACCELRANGE_2G:
555 case HWSPARKY2_ACCELRANGE_4G:
558 case HWSPARKY2_ACCELRANGE_8G:
561 case HWSPARKY2_ACCELRANGE_16G:
566 HwSparky2MPU9250GyroLPFOptions hw_mpu_dlpf;
567 HwSparky2MPU9250GyroLPFGet(&hw_mpu_dlpf);
568 uint16_t bandwidth = \
569 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_184) ? 184 : \
570 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_92) ? 92 : \
571 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_41) ? 41 : \
572 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_20) ? 20 : \
573 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_10) ? 10 : \
574 (hw_mpu_dlpf == HWSPARKY2_MPU9250GYROLPF_5) ? 5 : \
581 #if defined(PIOS_INCLUDE_I2C)
582 uint8_t hw_magnetometer;
583 HwSparky2MagnetometerGet(&hw_magnetometer);
586 switch (hw_magnetometer) {
587 case HWSPARKY2_MAGNETOMETER_NONE:
588 case HWSPARKY2_MAGNETOMETER_INTERNAL:
595 HwSparky2ExtMagPortOptions hw_mag_port;
596 HwSparky2ExtMagPortGet(&hw_mag_port);
599 const void *i2c_mag_cfg = NULL;
600 switch (hw_mag_port) {
601 case HWSPARKY2_EXTMAGPORT_FLEXIPORT:
602 if (hw_flexiport == HWSHARED_PORTTYPES_I2C) {
603 i2c_mag_id = pios_i2c_flexiport_adapter_id;
604 i2c_mag_cfg = &pios_i2c_flexiport_adapter_cfg;
607 case HWSPARKY2_EXTMAGPORT_AUXI2C:
608 i2c_mag_id = pios_i2c_mag_pressure_adapter_id;
609 i2c_mag_cfg = &pios_i2c_mag_pressure_adapter_cfg;
613 if (i2c_mag_id && i2c_mag_cfg) {
614 uint8_t hw_orientation;
615 HwSparky2ExtMagOrientationGet(&hw_orientation);
618 &i2c_mag_id, i2c_mag_cfg);
634 HwSparky2VTX_ChOptions channel;
635 HwSparky2VTX_ChGet(&channel);
int32_t PIOS_Flash_Internal_Init(uintptr_t *flash_id, const struct pios_flash_internal_cfg *cfg)
int32_t PIOS_USB_DESC_HID_CDC_Init(void)
void PIOS_HAL_ConfigureCDC(HwSharedUSB_VCPPortOptions port_type, uintptr_t usb_id, const struct pios_usb_cdc_cfg *cdc_cfg)
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_INTERNAL_ADC_Init(uintptr_t *internal_adc_id, const struct pios_internal_adc_cfg *cfg)
void set_vtx_channel(HwSparky2VTX_ChOptions channel)
int32_t PIOS_Flash_Jedec_Init(uintptr_t *flash_id, pios_spi_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg *cfg)
#define PIOS_DEBUG_Assert(test)
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
static const struct pios_usart_cfg pios_usart_main_cfg
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
uintptr_t pios_uavo_settings_fs_id
const struct pios_tim_channel * channels
uint16_t PIOS_IAP_ReadBootCount(void)
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t *fs_id, const struct flashfs_logfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
static const struct pios_tim_clock_cfg tim_8_cfg
const struct pios_board_info pios_board_info_blob
struct pios_mpu_dev * pios_mpu_dev_t
#define PIOS_COM_CAN_RX_BUF_LEN
#define PIOS_IRQ_PRIO_MID
Configuration structure for the MS5611 driver.
int32_t PIOS_I2C_Init(pios_i2c_t *i2c_id, const char *path)
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
int32_t PIOS_MPU_SPI_Init(pios_mpu_dev_t *dev, pios_spi_t spi_id, uint32_t slave_num, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on SPI.
void PIOS_DEBUG_Init(const struct pios_tim_channel *channels, uint8_t num_channels)
const struct pios_com_driver pios_usart_com_driver
static const struct pios_tim_clock_cfg tim_5_cfg
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
int32_t PIOS_MPU_SetAccelRange(enum pios_mpu_accel_range range)
const struct pios_adc_driver pios_internal_adc_driver
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
uintptr_t pios_internal_adc_id
struct pios_i2c_adapter * pios_i2c_t
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
const struct pios_usart_cfg * get_usart_rcvr_cfg(uint32_t board_revision)
Get the rcvr uart configuration.
#define PIOS_COM_CAN_TX_BUF_LEN
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
int32_t PIOS_SENSORS_Init()
Initialize the PIOS_SENSORS interface.
void PIOS_RTC_Init(const struct pios_rtc_cfg *cfg)
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
int32_t PIOS_CAN_Init(uintptr_t *id, const struct pios_can_cfg *cfg)
const struct pios_sbus_cfg * get_sbus_cfg(enum board_revision board_rev)
void PIOS_HAL_ConfigureHID(HwSharedUSB_HIDPortOptions port_type, uintptr_t usb_id, const struct pios_usb_hid_cfg *hid_cfg)
int32_t PIOS_Servo_Init(const struct pios_servo_cfg *cfg)
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
const struct pios_com_driver pios_can_com_driver
static const struct pios_usart_cfg pios_usart_flexi_cfg
#define BRUSHEDSPARKY_V0_2
uintptr_t pios_com_openlog_logging_id
static const struct pios_tim_clock_cfg tim_12_cfg
void PIOS_USBHOOK_Activate(void)
int32_t PIOS_COM_Init(uintptr_t *com_id, const struct pios_com_driver *driver, uintptr_t lower_id, uint16_t rx_buffer_len, uint16_t tx_buffer_len)
void PIOS_FLASH_register_partition_table(const struct pios_flash_partition partition_table[], uint8_t num_partitions)
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
int32_t PIOS_USB_Init(uintptr_t *usb_id, const struct pios_usb_cfg *cfg)
uint16_t PIOS_WDG_Init()
Initialize the watchdog timer for a specified timeout.
int32_t PIOS_ADC_Init(uintptr_t *adc_id, const struct pios_adc_driver *driver, uintptr_t lower_id)
void PIOS_IAP_WriteBootCount(uint16_t)
int32_t PIOS_MS5611_Init(const struct pios_ms5611_cfg *cfg, pios_i2c_t i2c_device)
static const struct pios_tim_clock_cfg tim_3_cfg
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
static const struct pios_tim_clock_cfg tim_9_cfg
const struct pios_servo_cfg * get_servo_cfg(uint32_t board_revision)
Get the flashfs settings.
#define PIOS_Assert(test)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
int32_t PIOS_USB_BOARD_DATA_Init(void)
static const struct pios_servo_cfg * servo_cfg
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.
void PIOS_SENSORS_SetMissing(enum pios_sensor_type type)
Assert that an optional (non-accel/gyro), but expected sensor is missing.
uintptr_t pios_com_can_id