omnibus: initial osd driver for omnibus board

This commit is contained in:
DanielePettenuzzo
2018-10-16 09:44:17 +02:00
committed by Daniele Pettenuzzo
parent 31f23c1e76
commit c3f9294b49
7 changed files with 963 additions and 0 deletions
+1
View File
@@ -42,6 +42,7 @@ px4_add_board(
#telemetry # all available telemetry drivers #telemetry # all available telemetry drivers
telemetry/frsky_telemetry telemetry/frsky_telemetry
#test_ppm #test_ppm
osd
MODULES MODULES
attitude_estimator_q attitude_estimator_q
+3
View File
@@ -167,6 +167,7 @@
#define GPIO_SPI3_MOSI_OFF _PIN_OFF(GPIO_SPI3_MOSI) #define GPIO_SPI3_MOSI_OFF _PIN_OFF(GPIO_SPI3_MOSI)
/* SPI 3 CS's off */ /* SPI 3 CS's off */
#define GPIO_SPI3_CS_BARO_OFF _PIN_OFF(GPIO_SPI3_CS_BARO) #define GPIO_SPI3_CS_BARO_OFF _PIN_OFF(GPIO_SPI3_CS_BARO)
#define GPIO_SPI3_CS_OSD_OFF _PIN_OFF(GPIO_SPI3_CS_OSD)
// One device per bus // One device per bus
#define PX4_SPI_BUS_SENSORS 1 #define PX4_SPI_BUS_SENSORS 1
@@ -174,6 +175,7 @@
#define PX4_SPIDEV_ICM_20602 1 #define PX4_SPIDEV_ICM_20602 1
#define PX4_SPIDEV_BARO_BUS 3 #define PX4_SPIDEV_BARO_BUS 3
#define PX4_SPIDEV_BARO 1 #define PX4_SPIDEV_BARO 1
#define PX4_SPIDEV_OSD 2
/* USB OTG FS /* USB OTG FS
* *
@@ -186,6 +188,7 @@
/*----------------------------------------------------------*/ /*----------------------------------------------------------*/
#define PX4_SPI_BUS_BARO 3 #define PX4_SPI_BUS_BARO 3
#define PX4_SPI_BUS_OSD 3
#define PX4_I2C_BUS_EXPANSION 2 #define PX4_I2C_BUS_EXPANSION 2
#define PX4_I2C_BUS_LED PX4_I2C_BUS_EXPANSION #define PX4_I2C_BUS_LED PX4_I2C_BUS_EXPANSION
+4
View File
@@ -76,6 +76,7 @@ __EXPORT void stm32_spiinitialize()
stm32_configgpio(GPIO_SPI_CS_MEMS); stm32_configgpio(GPIO_SPI_CS_MEMS);
stm32_configgpio(GPIO_SPI_CS_SDCARD); stm32_configgpio(GPIO_SPI_CS_SDCARD);
stm32_configgpio(GPIO_SPI3_CS_BARO); stm32_configgpio(GPIO_SPI3_CS_BARO);
stm32_configgpio(GPIO_SPI3_CS_OSD);
} }
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
@@ -107,6 +108,7 @@ __EXPORT void stm32_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool s
UNUSED(devid); UNUSED(devid);
/* SPI select is active low, so write !selected to select the device */ /* SPI select is active low, so write !selected to select the device */
px4_arch_gpiowrite(GPIO_SPI3_CS_BARO, !selected); px4_arch_gpiowrite(GPIO_SPI3_CS_BARO, !selected);
px4_arch_gpiowrite(GPIO_SPI3_CS_OSD, !selected);
} }
__EXPORT uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid) __EXPORT uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
@@ -138,6 +140,8 @@ __EXPORT void board_spi_reset(int ms)
/* disable SPI bus 3 CS */ /* disable SPI bus 3 CS */
stm32_configgpio(GPIO_SPI3_CS_BARO_OFF); stm32_configgpio(GPIO_SPI3_CS_BARO_OFF);
stm32_gpiowrite(GPIO_SPI3_CS_BARO_OFF, 0); stm32_gpiowrite(GPIO_SPI3_CS_BARO_OFF, 0);
stm32_configgpio(GPIO_SPI3_CS_OSD_OFF);
stm32_gpiowrite(GPIO_SPI3_CS_OSD_OFF, 0);
/* disable SPI bus 1*/ /* disable SPI bus 1*/
stm32_configgpio(GPIO_SPI1_SCK_OFF); stm32_configgpio(GPIO_SPI1_SCK_OFF);
+39
View File
@@ -0,0 +1,39 @@
############################################################################
#
# Copyright (c) 2018 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
px4_add_module(
MODULE drivers__osd
MAIN osd
SRCS
osd.cpp
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
File diff suppressed because it is too large Load Diff
+199
View File
@@ -0,0 +1,199 @@
/****************************************************************************
*
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
/**
* @file osd.h
* @author Daniele Pettenuzzo
*
* Driver for the ATXXXX chip on the omnibus fcu connected via SPI.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <perf/perf_counter.h>
#include <parameters/param.h>
#include <px4_getopt.h>
#include <px4_workqueue.h>
#include <board_config.h>
#include <drivers/drv_hrt.h>
#include <drivers/device/spi.h>
#include <uORB/uORB.h>
#include <uORB/topics/battery_status.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_status.h>
/* Configuration Constants */
#ifdef PX4_SPI_BUS_OSD
#define OSD_BUS PX4_SPI_BUS_OSD
#else
#error "add the required spi bus from board_config.h here"
#endif
#ifdef PX4_SPIDEV_OSD
#define OSD_SPIDEV PX4_SPIDEV_OSD
#else
#error "add the required spi bus from board_config.h here"
#endif
#define OSD_SPI_BUS_SPEED (2000000L) /* 2 MHz */
#define DIR_READ(a) ((a) | (1 << 7))
#define DIR_WRITE(a) ((a) & 0x7f)
#define OSD_DEVICE_PATH "/dev/osd"
#define OSD_US 1000 /* 1 ms */
#define OSD_UPDATE_RATE 500000 /* 2 Hz */
#define OSD_CHARS_PER_ROW 30
#define OSD_ZERO_BYTE 0x00
#define OSD_PAL_TX_MODE 0x40
/* OSD Registers addresses */
#ifndef CONFIG_SCHED_WORKQUEUE
# error This requires CONFIG_SCHED_WORKQUEUE.
#endif
class OSD : public device::SPI
{
public:
OSD(int bus = OSD_BUS);
virtual ~OSD();
virtual int init();
virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen);
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
/**
* Diagnostics - print some basic information about the driver.
*/
void print_info();
/**
* Initialise the automatic measurement state machine and start it.
*
* @note This function is called at open and error time. It might make sense
* to make it more aggressive about resetting the bus in case of errors.
*/
void start();
protected:
virtual int probe();
private:
work_s _work;
int _measure_ticks;
perf_counter_t _sample_perf;
perf_counter_t _comms_errors;
param_t _p_tx_mode;
int32_t _tx_mode;
int _battery_sub;
int _local_position_sub;
int _vehicle_status_sub;
bool _on;
// battery
float _battery_voltage_filtered_v;
float _battery_discharge_mah;
bool _battery_valid;
// altitude
float _local_position_z;
bool _local_position_valid;
// flight time
uint8_t _arming_state;
uint64_t _arming_timestamp;
/**
* Stop the automatic measurement state machine.
*/
void stop();
/**
* Perform a poll cycle; collect from the previous measurement
* and start a new one.
*/
void cycle();
int reset();
int init_osd();
int readRegister(unsigned reg, uint8_t *data, unsigned count);
int writeRegister(unsigned reg, uint8_t data);
int add_character_to_screen(char c, uint8_t pos_x, uint8_t pos_y);
int add_battery_symbol(uint8_t pos_x, uint8_t pos_y);
int add_battery_info(uint8_t pos_x, uint8_t pos_y);
int add_altitude_symbol(uint8_t pos_x, uint8_t pos_y);
int add_altitude(uint8_t pos_x, uint8_t pos_y);
int add_flighttime_symbol(uint8_t pos_x, uint8_t pos_y);
int add_flighttime(float flight_time, uint8_t pos_x, uint8_t pos_y);
int enable_screen();
int disable_screen();
int update_topics();
int update_screen();
/**
* Static trampoline from the workq context; because we don't have a
* generic workq wrapper yet.
*
* @param arg Instance pointer for the driver that is polling.
*/
static void cycle_trampoline(void *arg);
};
/*
* Driver 'main' command.
*/
extern "C" __EXPORT int osd_main(int argc, char *argv[]);
+45
View File
@@ -0,0 +1,45 @@
/****************************************************************************
*
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* ATXXX OSD Chip
*
* Select Transmission Standard
*
* @value 0 NTSC
* @value 1 PAL
*
* @reboot_required true
*
*/
PARAM_DEFINE_INT32(OSD_TX_MODE, 0);