57 #ifdef PIOS_INCLUDE_MAX7456
64 #define MAX7456_DEFAULT_BRIGHTNESS 0x00
66 #define MAX7456_MASK_PAL MAX7456_VM0_VSS_MASK
67 #define MAX7456_MASK_NTSC 0x00
69 #define SYNC_INTERVAL_NTSC 33366
70 #define SYNC_INTERVAL_PAL 40000
74 struct max7456_dev_s {
75 #define MAX7456_MAGIC 0x36353437
80 uint8_t
mode, right, bottom, hcenter, vcenter;
86 uint8_t det_mode_fallback;
88 uint32_t next_sync_expected;
96 #define MAX7456_SPI_SPEED 9000000
116 #define enable_osd(dev) do { write_register_sel(dev, MAX7456_REG_VM0, dev->mask | MAX7456_VM0_OSD_MASK | MAX7456_VM0_VS_MASK); } while (0)
117 #define disable_osd(dev) do { write_register_sel(dev, MAX7456_REG_VM0, 0); } while (0)
127 static uint8_t read_register_sel(
max7456_dev_t dev, uint8_t reg)
132 ret = read_register(dev, reg);
138 static void write_register(
max7456_dev_t dev, uint8_t reg, uint8_t val)
144 static void write_register_sel(
max7456_dev_t dev, uint8_t reg, uint8_t val)
147 write_register(dev, reg, val);
161 dev->mask = MAX7456_MASK_NTSC;
171 dev->mask = MAX7456_MASK_PAL;
185 if (!dev->force_mode) {
203 set_mode(dev, dev->det_mode_fallback);
223 uint32_t sync_interval =
227 if (now > dev->next_sync_expected) {
229 dev->next_sync_expected += sync_interval;
232 if (now > dev->next_sync_expected) {
234 dev->next_sync_expected = now + sync_interval;
237 while (!poll_vsync_spi(dev)) {
240 if (now + 200 > (dev->next_sync_expected + sync_interval)) {
251 dev->next_sync_expected = now + sync_interval;
256 dev->next_sync_expected = 0;
267 auto_black_level(dev,
true);
280 uint8_t brightness = MAX7456_DEFAULT_BRIGHTNESS;
283 write_register_sel(dev, r, brightness);
295 bzero(dev,
sizeof(*dev));
296 dev->magic = MAX7456_MAGIC;
297 dev->spi_id = spi_handle;
298 dev->slave_id = slave_idx;
299 dev->force_mode =
false;
311 dev->force_mode = force;
312 dev->det_mode_fallback = fallback;
346 for (uint8_t
i = 0;
i < 54;
i ++)
399 for (uint8_t
i = 0;
i < 54;
i ++)
411 static inline void set_offset (
max7456_dev_t dev, uint8_t col, uint8_t row)
420 uint16_t
offset = (row * 30 + col) & 0x1ff;
433 uint8_t col, uint8_t row, uint8_t chr, uint8_t attr)
440 set_offset(dev, col, row);
446 static void PIOS_MAX7456_open (
max7456_dev_t dev, uint8_t col, uint8_t row,
456 set_offset(dev, col > dev->right ? 0 : col, row > dev->bottom ? 0 : row);
475 #define valid_char(c) (c == MAX7456_DMDI_AUTOINCREMENT_STOP ? 0x00 : c)
483 PIOS_MAX7456_open(dev, col, row, attr);
489 PIOS_MAX7456_close(dev);
493 uint8_t *
mode, uint8_t *right, uint8_t *bottom,
494 uint8_t *hcenter, uint8_t *vcenter)
511 *hcenter=dev->hcenter;
515 *vcenter=dev->vcenter;
#define MAX7456_PAL_COLUMNS
#define MAX7456_DMM_CLR_READY
#define MAX7456_VM1_BGLVL_42
uint32_t PIOS_DELAY_GetuS()
Query the Delay timer for the current uS.
Main PiOS header to include all the compiled in PiOS options.
#define MAX7456_DMDI_AUTOINCREMENT_STOP
#define MAX7456_DMM_CLR_W(regval, val)
int32_t PIOS_SPI_RC_PinSet(pios_spi_t spi_dev, uint32_t slave_id, bool pin_value)
#define MAX7456_VM1_BGLVL_W(regval, val)
bool PIOS_MAX7456_stall_detect(max7456_dev_t dev)
Detects whether the OSD chip has stalled and attempts to restart it.
#define MAX7456_OSDBL_CTL_ENABLE
#define MAX7456_VM0_VSS_PAL
int32_t PIOS_SPI_ClaimBus(pios_spi_t spi_dev)
#define MAX7456_PAL_HCENTER
void * PIOS_malloc(size_t size)
#define MAX7456_VM0_VSS_W(regval, val)
#define MAX7456_VM1_BTIME_W(regval, val)
#define MAX7456_VM0_VSS_NTSC
#define MAX7456_STAT_NTSC_TRUE
#define MAX7456_PAL_VCENTER
struct max7456_dev_s * max7456_dev_t
void PIOS_MAX7456_put(max7456_dev_t dev, uint8_t col, uint8_t row, uint8_t chr, uint8_t attr)
Sets a position of character memory.
uint8_t data[XFER_BYTES_PER_PACKET]
#define MAX7456_DMM_CLR_R(val)
#define MAX7456_STAT_VSYNC_R(val)
#define MAX7456_STAT_VSYNC_TRUE
void PIOS_MAX7456_set_mode(max7456_dev_t dev, bool force, uint8_t fallback)
Allows overriding the video mode used by OSD.
void PIOS_MAX7456_puts(max7456_dev_t dev, uint8_t col, uint8_t row, const char *s, uint8_t attr)
Sets a string into character memory.
#define MAX7456_MODE_NTSC
#define MAX7456_STAT_PAL_TRUE
uint8_t PIOS_SPI_TransferByte(pios_spi_t spi_dev, uint8_t b)
int32_t PIOS_SPI_SetClockSpeed(pios_spi_t spi_dev, uint32_t speed)
void PIOS_MAX7456_get_extents(max7456_dev_t dev, uint8_t *mode, uint8_t *right, uint8_t *bottom, uint8_t *hcenter, uint8_t *vcenter)
Gets the extents of the screen.
#define MAX7456_VM0_SRB_R(val)
static void set_mode(charosd_state_t state, uint8_t video_std)
#define MAX7456_VM1_BGMODE_LOCAL
void PIOS_MAX7456_clear(max7456_dev_t dev)
Clear the screen.
#define MAX7456_OSDBL_CTL_W(regval, val)
#define MAX7456_CMM_READ_NVM
#define MAX7456_VM0_OSD_MASK
void PIOS_MAX7456_download_char(max7456_dev_t dev, uint8_t char_index, uint8_t *data)
Download a character from the device.
#define MAX7456_OSDBL_CTL_DISABLE
#define MAX7456_VM1_BGMODE_W(regval, val)
#define MAX7456_VM0_SRB_MASK
void PIOS_Thread_Sleep(uint32_t time_ms)
#define MAX7456_CMM_WRITE_NVM
#define MAX7456_VM0_SRB_RESET
#define MAX7456_STAT_NTSC_R(val)
#define MAX7456_FMT_H_CENTER
#define MAX7456_NTSC_HCENTER
#define MAX7456_VM1_BDUTY_13BT
#define MAX7456_STAT_PAL_R(val)
#define MAX7456_VM0_SRB_W(regval, val)
#define MAX7456_STAT_CHMEM_BUSY
void PIOS_MAX7456_upload_char(max7456_dev_t dev, uint8_t char_index, const uint8_t *data)
Upload a character to the device.
int32_t PIOS_SPI_ReleaseBus(pios_spi_t spi_dev)
#define MAX7456_DMM_CLR_CLEAR
#define MAX7456_VM1_BTIME_6FIELD
#define MAX7456_NTSC_COLUMNS
#define MAX7456_VM1_BDUTY_W(regval, val)
#define PIOS_Assert(test)
int PIOS_MAX7456_init(max7456_dev_t *dev_out, pios_spi_t spi_handle, uint32_t slave_idx)
Allocate and initialise MAX7456 device.
void PIOS_MAX7456_wait_vsync()
#define MAX7456_NTSC_ROWS
int32_t PIOS_DELAY_WaituS(uint32_t uS)
#define MAX7456_STAT_CHMEM_R(val)
#define MAX7456_NTSC_VCENTER