From 28b7b60f6ad9c755cb330b9ad37df79b25ea6004 Mon Sep 17 00:00:00 2001 From: BlastBrothers <83738994+BlastBrothers@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:05:49 -0400 Subject: [PATCH] Update MOS sysvars struct (RTC, mouse) (#16) Update mos_api.h --- include/mos_api.h | 22 +++++++++++++++-- src/libc/include/mos_api.h | 49 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/include/mos_api.h b/include/mos_api.h index d92e5bd..994c158 100644 --- a/include/mos_api.h +++ b/include/mos_api.h @@ -2,7 +2,7 @@ * Title: AGON MOS - MOS c header interface * Author: Jeroen Venema * Created: 15/10/2022 - * Last Updated: 18/11/2023 + * Last Updated: 05/04/2024 * * Modinfo: * 15/10/2022: Added putch, getch @@ -14,6 +14,7 @@ * 02/07/2023: Added struct / union for RTC_DATA * 22/07/2023: Added structure for SYSVAR * 18/11/2023: Added mos_setkbvector, mos_getkbmap, mos_i2c_open, mos_i2c_close, mos_i2c_write, mos_i2c_read + * 05/04/2024: Added more mos sysvars, and expanded SYSVAR struct */ #ifndef _MOS_H @@ -91,6 +92,15 @@ typedef enum { #define sysvar_keydelay 0x22 // 2: Keyboard repeat delay #define sysvar_keyrate 0x24 // 2: Keyboard repeat reat #define sysvar_keyled 0x26 // 1: Keyboard LED status +//TODO: for scrMode and below, we need to write getters +#define sysvar_scrMode 0x27 // 1: Screen mode +#define sysvar_rtcEnable 0x28 // 1: RTC enable flag (0: disabled, 1: use ESP32 RTC) +#define sysvar_mouseX 0x29 // 2: Mouse X position +#define sysvar_mouseY 0x2B // 2: Mouse Y position +#define sysvar_mouseButtons 0x2D // 1: Mouse button state +#define sysvar_mouseWheel 0x2E // 1: Mouse wheel delta +#define sysvar_mouseXDelta 0x2F // 2: Mouse X delta +#define sysvar_mouseYDelta 0x31 // 2: Mouse Y delta // Flags for the VPD protocol - sysvar_vpd_pflags #define vdp_pflag_cursor 0x01 @@ -99,6 +109,7 @@ typedef enum { #define vdp_pflag_audio 0x08 #define vdp_pflag_mode 0x10 #define vdp_pflag_rtc 0x20 +#define vdp_pflag_mouse 0x40 // Stucture / union for accessing RTC data @@ -150,6 +161,13 @@ typedef struct { uint16_t keyrate; uint8_t keyled; uint8_t scrMode; + uint8_t rtcEnable; + uint16_t mouseX; + uint16_t mouseY; + uint8_t mouseButtons; + uint8_t mouseWheel; + uint16_t mouseXDelta; + uint16_t mouseYDelta; } SYSVAR; @@ -260,4 +278,4 @@ extern uint8_t mos_i2c_read(uint8_t i2c_address, uint8_t size, unsigned char * } #endif -#endif // _MOS_H \ No newline at end of file +#endif // _MOS_H diff --git a/src/libc/include/mos_api.h b/src/libc/include/mos_api.h index 610adc9..994c158 100644 --- a/src/libc/include/mos_api.h +++ b/src/libc/include/mos_api.h @@ -2,7 +2,7 @@ * Title: AGON MOS - MOS c header interface * Author: Jeroen Venema * Created: 15/10/2022 - * Last Updated: 22/07/2023 + * Last Updated: 05/04/2024 * * Modinfo: * 15/10/2022: Added putch, getch @@ -13,6 +13,8 @@ * 19/04/2023: Added mos_getfil * 02/07/2023: Added struct / union for RTC_DATA * 22/07/2023: Added structure for SYSVAR + * 18/11/2023: Added mos_setkbvector, mos_getkbmap, mos_i2c_open, mos_i2c_close, mos_i2c_write, mos_i2c_read + * 05/04/2024: Added more mos sysvars, and expanded SYSVAR struct */ #ifndef _MOS_H @@ -30,6 +32,17 @@ typedef uint8_t BYTE; #define FA_OPEN_ALWAYS 0x10 #define FA_OPEN_APPEND 0x30 +// I2C frequency +#define I2C_SPEED_57600 0x01 +#define I2C_SPEED_115200 0x02 +#define I2C_SPEED_230400 0x03 +// I2C return codes to caller +#define RET_OK 0x00 +#define RET_NORESPONSE 0x01 +#define RET_DATA_NACK 0x02 +#define RET_ARB_LOST 0x04 +#define RET_BUS_ERROR 0x08 + /* FatFS File function return code (FRESULT) */ typedef enum { @@ -79,6 +92,15 @@ typedef enum { #define sysvar_keydelay 0x22 // 2: Keyboard repeat delay #define sysvar_keyrate 0x24 // 2: Keyboard repeat reat #define sysvar_keyled 0x26 // 1: Keyboard LED status +//TODO: for scrMode and below, we need to write getters +#define sysvar_scrMode 0x27 // 1: Screen mode +#define sysvar_rtcEnable 0x28 // 1: RTC enable flag (0: disabled, 1: use ESP32 RTC) +#define sysvar_mouseX 0x29 // 2: Mouse X position +#define sysvar_mouseY 0x2B // 2: Mouse Y position +#define sysvar_mouseButtons 0x2D // 1: Mouse button state +#define sysvar_mouseWheel 0x2E // 1: Mouse wheel delta +#define sysvar_mouseXDelta 0x2F // 2: Mouse X delta +#define sysvar_mouseYDelta 0x31 // 2: Mouse Y delta // Flags for the VPD protocol - sysvar_vpd_pflags #define vdp_pflag_cursor 0x01 @@ -87,6 +109,7 @@ typedef enum { #define vdp_pflag_audio 0x08 #define vdp_pflag_mode 0x10 #define vdp_pflag_rtc 0x20 +#define vdp_pflag_mouse 0x40 // Stucture / union for accessing RTC data @@ -138,6 +161,13 @@ typedef struct { uint16_t keyrate; uint8_t keyled; uint8_t scrMode; + uint8_t rtcEnable; + uint16_t mouseX; + uint16_t mouseY; + uint8_t mouseButtons; + uint8_t mouseWheel; + uint16_t mouseXDelta; + uint16_t mouseYDelta; } SYSVAR; @@ -173,6 +203,10 @@ typedef struct { uint24_t* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ } FIL; +#ifdef __cplusplus +extern "C" { +#endif + // Generic IO extern int putch(int a); extern char getch(void); @@ -233,4 +267,15 @@ extern uint24_t mos_fread(uint8_t fh, char *buffer, uint24_t numbytes); extern uint24_t mos_fwrite(uint8_t fh, char *buffer, uint24_t numbytes); extern uint8_t mos_flseek(uint8_t fh, uint32_t offset); extern FIL* mos_getfil(uint8_t fh); -#endif \ No newline at end of file +extern void mos_setkbvector(void(*handler)(void), uint8_t addresslength); // length 0:24bit, 1:16bit +extern uint8_t* mos_getkbmap(void); // returns address of the keyboard map +extern void mos_i2c_open(uint8_t frequency); +extern void mos_i2c_close(void); +extern uint8_t mos_i2c_write(uint8_t i2c_address, uint8_t size, unsigned char * buffer); +extern uint8_t mos_i2c_read(uint8_t i2c_address, uint8_t size, unsigned char * buffer); + +#ifdef __cplusplus +} +#endif + +#endif // _MOS_H