laptop_io.h
Go to the documentation of this file.
#include <gbdk/platform.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef _MEGADUCK_LAPTOP_IO_H
#define _MEGADUCK_LAPTOP_IO_H
// Commands sent via serial IO to the Duck laptop peripheral hardware
#define DUCK_IO_CMD_INIT_START 0x00u
#define DUCK_IO_CMD_GET_KEYS 0x00u
#define DUCK_IO_CMD_DONE_OR_OK 0x01u
// #define DUCK_IO_CMD_DONE_OR_OK_AND_SOMETHING 0x81u
#define DUCK_IO_CMD_ABORT_OR_FAIL 0x04u
#define DUCK_IO_CMD_PLAY_SPEECH 0x05u
#define DUCK_IO_CMD_RUN_CART_IN_SLOT 0x08u
#define DUCK_IO_CMD_PRINT_INIT_EXT_IO 0x09u
#define DUCK_IO_CMD_SET_RTC 0x0Bu
#define DUCK_IO_CMD_GET_RTC 0x0Cu
#define DUCK_IO_CMD_PRINT_SEND_BYTES 0x11u
// #define FF60_REG_BEFORE_XFER 0x00u
#define DUCK_IO_REPLY_BOOT_UNSET 0x00u
#define DUCK_IO_REPLY_BOOT_FAIL 0x01u
#define DUCK_IO_REPLY_BUFFER_XFER_OK 0x01u
#define DUCK_IO_REPLY_SEND_BUFFER_OK 0x03u
// #define DUCK_IO_REPLY_READ_FAIL_MAYBE 0x00u
#define DUCK_IO_REPLY_BOOT_OK 0x01u
#define DUCK_IO_LEN_KBD_GET 2u
#define DUCK_IO_LEN_RTC_GET 8u
#define DUCK_IO_LEN_RTC_SET 8u
#define DUCK_IO_LEN_PLAY_SPEECH 1u
#define DUCK_IO_REPLY_NO_CART_IN_SLOT 06u
// #define MEGADUCK_KBD_BYTE_1_EXPECT 0x0Eu
// #define MEGADUCK_SIO_BOOT_OK 0x01u
#define DUCK_IO_LEN_RX_MAX 14u // 13 data bytes + 1 checksum byte max reply length?
#define DUCK_IO_LEN_TX_MAX 14u // 13 data bytes + 1 checksum byte max reply length?
#define DUCK_IO_TIMEOUT_2_MSEC 2u // Used for hardware init counter sequence
#define DUCK_IO_TIMEOUT_100_MSEC 100u
#define DUCK_IO_TIMEOUT_200_MSEC 200u
// Pre-recorded Speech Samples for playback
#define DUCK_IO_SPEECH_CMD_MIN 1
#define DUCK_IO_SPEECH_CMD_MAX 6
// RTC packet byte ordering (all in BCD format)
#define DUCK_IO_RTC_YEAR 0u
#define DUCK_IO_RTC_MON 1u
#define DUCK_IO_RTC_DAY 2u
#define DUCK_IO_RTC_WEEKDAY 3u
#define DUCK_IO_RTC_AMPM 4u
#define DUCK_IO_RTC_HOUR 5u
#define DUCK_IO_RTC_MIN 6u
#define DUCK_IO_RTC_SEC 7u
// Keyboard packet byte ordering (all in BCD format)
#define DUCK_IO_KBD_FLAGS 0u
#define DUCK_IO_KBD_KEYCODE 1u
// Printer init reply related
// Init Reply Bits:1..0
#define DUCK_IO_PRINTER_FAIL 0x00u
#define DUCK_IO_PRINTER_TYPE_2_PASS 0x01u // Bit.1 = 0 // 13 x 12 byte packets + 1 x 5 or 6 byte packet (with CR and/or LF)
#define DUCK_IO_PRINTER_TYPE_1_PASS 0x02u // Bit.1 = 1 // 3 x 12 byte packets + 118 non-packet bytes
#define DUCK_IO_PRINTER_MAYBE_BUSY 0x03u // Maybe indicating that Printer Type 1 is busy?
extern volatile bool duck_io_rx_byte_done;
extern volatile uint8_t duck_io_rx_byte;
// TODO: change these to user supplied buffers?
extern uint8_t duck_io_rx_buf[DUCK_IO_LEN_RX_MAX];
extern uint8_t duck_io_rx_buf_len;
extern uint8_t duck_io_tx_buf[DUCK_IO_LEN_TX_MAX];
extern uint8_t duck_io_tx_buf_len;
// ===== Low level helper IO functions =====
// TODO: No longer in use(?)
//
// Waits for a serial transfer to complete with a timeout
//
// @param timeout_len_ms Unit size is in msec (100 is about ~ 103 msec or 6.14 frames)
//
// Serial ISR populates status var if anything was received
//
// void duck_io_wait_done_with_timeout(uint8_t timeout_len_ms);
void duck_io_send_byte(uint8_t tx_byte);
uint8_t duck_io_read_byte_no_timeout(void);
void duck_io_enable_read_byte(void);
bool duck_io_laptop_init(void);
uint8_t duck_io_printer_last_status(void);
uint8_t duck_io_printer_query(void);
// ===== Higher level IO functions =====
bool duck_io_read_byte_with_msecs_timeout(uint8_t timeout_len_ms);
bool duck_io_send_byte_and_check_ack_msecs_timeout(uint8_t tx_byte, uint8_t timeout_len_ms, uint8_t expected_reply);
bool duck_io_send_cmd_and_buffer(uint8_t io_cmd);
bool duck_io_send_cmd_and_receive_buffer(uint8_t io_cmd);
#endif // _MEGADUCK_LAPTOP_IO_H
DUCK_IO_LEN_RX_MAX
#define DUCK_IO_LEN_RX_MAX
Definition: laptop_io.h:62
DUCK_IO_LEN_TX_MAX
#define DUCK_IO_LEN_TX_MAX
Definition: laptop_io.h:63
duck_io_enable_read_byte
void duck_io_enable_read_byte(void)
duck_io_laptop_init
bool duck_io_laptop_init(void)
duck_io_printer_last_status
uint8_t duck_io_printer_last_status(void)
duck_io_printer_query
uint8_t duck_io_printer_query(void)
duck_io_read_byte_no_timeout
uint8_t duck_io_read_byte_no_timeout(void)
duck_io_read_byte_with_msecs_timeout
bool duck_io_read_byte_with_msecs_timeout(uint8_t timeout_len_ms)
duck_io_rx_buf
uint8_t duck_io_rx_buf[DUCK_IO_LEN_RX_MAX]
duck_io_rx_buf_len
uint8_t duck_io_rx_buf_len
duck_io_rx_byte
volatile uint8_t duck_io_rx_byte
duck_io_rx_byte_done
volatile bool duck_io_rx_byte_done
duck_io_send_byte
void duck_io_send_byte(uint8_t tx_byte)
duck_io_send_byte_and_check_ack_msecs_timeout
bool duck_io_send_byte_and_check_ack_msecs_timeout(uint8_t tx_byte, uint8_t timeout_len_ms, uint8_t expected_reply)
duck_io_send_cmd_and_buffer
bool duck_io_send_cmd_and_buffer(uint8_t io_cmd)
duck_io_send_cmd_and_receive_buffer
bool duck_io_send_cmd_and_receive_buffer(uint8_t io_cmd)
duck_io_tx_buf
uint8_t duck_io_tx_buf[DUCK_IO_LEN_TX_MAX]
duck_io_tx_buf_len
uint8_t duck_io_tx_buf_len
platform.h
stdbool.h
stdint.h
uint8_t
unsigned char uint8_t
Definition: stdint.h:51