42 #include "board_hw_defs.c"
48 #include <uavobjectsinit.h>
51 #include "hwbrainre1.h"
52 #include "flightbatterysettings.h"
53 #include "flightstatus.h"
54 #include "modulesettings.h"
55 #include "manualcontrolsettings.h"
56 #include "onscreendisplaysettings.h"
57 #include "rgbledsettings.h"
73 void *ctx,
void *obj,
int len)
75 (void) ev; (void) ctx; (void) len;
77 HwBrainRE1Data * hwre1data = (HwBrainRE1Data *)obj;
82 switch (hwre1data->IRProtocol) {
83 case HWBRAINRE1_IRPROTOCOL_DISABLED:
86 case HWBRAINRE1_IRPROTOCOL_ILAP:
91 case HWBRAINRE1_IRPROTOCOL_TRACKMATE:
99 if (hwre1data->BuzzerType == HWBRAINRE1_BUZZERTYPE_4KHZ_BUZZER) {
102 else if (hwre1data->BuzzerType == HWBRAINRE1_BUZZERTYPE_DC_BUZZER) {
118 #if defined(PIOS_INCLUDE_ANNUNC)
122 #if defined(PIOS_INCLUDE_SPI)
128 if (
PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
133 #if defined(PIOS_INCLUDE_RE1_FPGA)
139 #if defined(PIOS_INCLUDE_FLASH)
153 #if defined(ERASE_FLASH)
159 HwBrainRE1Initialize();
166 HwBrainRE1HWRevisionSet(&hw_rev);
169 uint8_t flashid[16] = {0};
171 HwBrainRE1FlashIDSet(flashid);
173 ModuleSettingsInitialize();
175 #if defined(PIOS_INCLUDE_RTC)
184 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
202 if (boot_count < 3) {
207 HwBrainRE1SetDefaults(HwBrainRE1Handle(), 0);
208 ModuleSettingsSetDefaults(ModuleSettingsHandle(),0);
209 AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
212 #if defined(PIOS_INCLUDE_USB)
217 bool usb_hid_present =
false;
218 bool usb_cdc_present =
false;
220 #if defined(PIOS_INCLUDE_USB_CDC)
224 usb_hid_present =
true;
225 usb_cdc_present =
true;
230 usb_hid_present =
true;
233 uintptr_t pios_usb_id;
236 #if defined(PIOS_INCLUDE_USB_CDC)
238 uint8_t hw_usb_vcpport;
240 HwBrainRE1USB_VCPPortGet(&hw_usb_vcpport);
242 if (!usb_cdc_present) {
244 hw_usb_vcpport = HWBRAINRE1_USB_VCPPORT_DISABLED;
250 #if defined(PIOS_INCLUDE_USB_HID)
252 uint8_t hw_usb_hidport;
253 HwBrainRE1USB_HIDPortGet(&hw_usb_hidport);
255 if (!usb_hid_present) {
257 hw_usb_hidport = HWBRAINRE1_USB_HIDPORT_DISABLED;
263 if (usb_hid_present || usb_cdc_present) {
271 HwBrainRE1DSMxModeOptions hw_DSMxMode;
272 HwBrainRE1DSMxModeGet(&hw_DSMxMode);
275 HwBrainRE1RxPortGet(&hw_rxport);
277 PIOS_HAL_ConfigurePort(hw_rxport,
285 &pios_rxport_dsm_cfg,
289 if (hw_rxport == HWSHARED_PORTTYPES_SBUS) {
295 HwBrainRE1SerialPortGet(&hw_sp);
297 PIOS_HAL_ConfigurePort(hw_sp,
311 HwBrainRE1MultiPortModeGet(&hw_mp_mode);
312 uint8_t hw_mp_serial;
313 HwBrainRE1MultiPortSerialGet(&hw_mp_serial);
316 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
318 #if defined(PIOS_INCLUDE_DMASHOT)
320 #endif // defined(PIOS_INCLUDE_DMASHOT)
322 switch (hw_mp_mode) {
323 case HWBRAINRE1_MULTIPORTMODE_NORMAL:
324 if (hw_mp_serial == HWBRAINRE1_MULTIPORTSERIAL_PWM) {
333 case HWBRAINRE1_MULTIPORTMODE_DUALSERIAL4PWM:
341 switch (hw_mp_serial) {
342 case HWBRAINRE1_MULTIPORTSERIAL_PWM:
346 PIOS_HAL_ConfigurePort(hw_mp_serial,
361 switch (hw_mp_serial) {
362 case HWBRAINRE1_MULTIPORTSERIAL_FRSKYSENSORHUB:
365 case HWBRAINRE1_MULTIPORTSERIAL_FRSKYSPORTTELEMETRY:
372 if (hw_mp_mode == HWBRAINRE1_MULTIPORTMODE_DUALSERIAL4PWM) {
373 HwBrainRE1MultiPortSerial2Get(&hw_mp_serial);
375 PIOS_HAL_ConfigurePort(hw_mp_serial,
395 RGBLEDSettingsInitialize();
396 RGBLEDSettingsNumLedsGet(&num_leds);
401 #if defined(PIOS_INCLUDE_ADC)
402 uintptr_t internal_adc_id;
407 #if defined(PIOS_INCLUDE_SPI)
408 #if defined(PIOS_INCLUDE_BMI160)
410 HwBrainRE1BMI160FOCGet(&bmi160_foc);
412 bool do_foc = (bmi160_foc == HWBRAINRE1_BMI160FOC_DO_FOC);
420 bmi160_foc = HWBRAINRE1_BMI160FOC_DISABLED;
421 HwBrainRE1BMI160FOCSet(&bmi160_foc);
428 uint8_t hw_orientation;
430 HwBrainRE1I2CExtMagGet(&hw_ext_mag);
431 HwBrainRE1ExtMagOrientationGet(&hw_orientation);
434 &pios_i2c_external_id, &pios_i2c_external_cfg);
438 HwBrainRE1I2CExtBaroGet(&hw_ext_baro);
441 &pios_i2c_external_id, &pios_i2c_external_cfg);
444 FlightBatterySettingsInitialize();
445 FlightBatterySettingsData batterysettings;
446 FlightBatterySettingsGet(&batterysettings);
447 if(batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_CURRENT] == 36.6f) {
448 batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_CURRENT] = 25.0f;
451 if(batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_VOLTAGE] == 63.69f) {
452 batterysettings.SensorCalibrationFactor[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONFACTOR_VOLTAGE] = 152.0f;
454 FlightBatterySettingsSet(&batterysettings);
int32_t PIOS_RE1FPGA_Init(pios_spi_t spi_id, uint32_t slave_num, const struct pios_re1fpga_cfg *cfg, bool load_config)
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)
Generate packets for various infrared lap timin protocols.
void PIOS_HAL_ConfigureCDC(HwSharedUSB_VCPPortOptions port_type, uintptr_t usb_id, const struct pios_usb_cdc_cfg *cdc_cfg)
int32_t PIOS_BMI160_Init(pios_spi_t spi_id, uint32_t slave_num, const struct pios_bmi160_cfg *cfg, bool do_foc)
int32_t PIOS_RE1FPGA_SetBuzzerType(enum pios_re1fpga_buzzer_types type)
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)
int PIOS_HAL_ConfigureExternalBaro(HwSharedExtBaroOptions baro, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
void pios_ir_generate_trackmate_packet(uint16_t trackmate_id, uint8_t *data, uint8_t data_len)
static void settingsUpdatedCb(const UAVObjEvent *ev, void *ctx, void *obj, int len)
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)
const struct pios_servo_cfg pios_servo_8_cfg
Brushed Sparky skips last two output ports.
int PIOS_HAL_ConfigureExternalMag(HwSharedMagOptions mag, HwSharedMagOrientationOptions orientation, pios_i2c_t *i2c_id, const struct pios_i2c_adapter_cfg *i2c_cfg)
int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
uintptr_t pios_uavo_settings_fs_id
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
int PIOS_WS2811_init(ws2811_dev_t *dev_out, const struct pios_ws2811_cfg *cfg, int max_leds)
Allocate and initialise WS2811 device.
int32_t PIOS_Flash_Jedec_ReadOTPData(uintptr_t chip_id, uint32_t chip_offset, uint8_t *data, uint16_t len)
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
int32_t PIOS_RE1FPGA_MPTxPinMode(bool bidrectional, bool invert)
const struct pios_com_driver pios_usart_com_driver
Driver for talking to most JEDEC flash chips.
static const struct pios_tim_clock_cfg tim_5_cfg
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
const struct pios_adc_driver pios_internal_adc_driver
int32_t PIOS_RE1FPGA_SetSyncThreshold(uint8_t threshold)
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
uintptr_t pios_internal_adc_id
int32_t PIOS_SPI_Init(pios_spi_t *spi_dev, const struct pios_spi_cfg *cfg)
int32_t PIOS_ANNUNC_Init(const struct pios_annunc_cfg *cfg)
uint8_t PIOS_RE1FPGA_GetHWRevision()
static const struct pios_tim_clock_cfg tim_1_cfg
void pios_ir_generate_ilap_packet(uint32_t ilap_id, uint8_t *data, uint8_t data_len)
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)
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)
int32_t PIOS_RE1FPGA_SetIRProtocol(enum pios_re1fpga_ir_protocols ir_protocol)
uintptr_t pios_com_openlog_logging_id
int32_t PIOS_RE1FPGA_MPTxPinPullUpDown(bool enable, bool pullup)
uintptr_t pios_com_logging_id
static const struct pios_tim_clock_cfg tim_12_cfg
void PIOS_USBHOOK_Activate(void)
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)
const struct pios_flash_partition pios_flash_partition_table[]
void PIOS_IAP_WriteBootCount(uint16_t)
int32_t PIOS_RE1FPGA_SerialRxInvert(bool invert)
void PIOS_HAL_CriticalError(uint32_t led_id, enum pios_hal_panic code)
Flash a blink code.
int32_t PIOS_FLASHFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
void PIOS_DMAShot_Init(const struct pios_dmashot_cfg *config)
Initializes the DMAShot driver by loading the configuration.
int32_t PIOS_RE1FPGA_SetIRData(const uint8_t *ir_data, uint8_t n_bytes)
#define PIOS_Assert(test)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_USB_BOARD_DATA_Init(void)
void PIOS_RESET_Clear(void)
PIOS_RESET_Clear Does nothing on POSIX systems.