1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-30 13:52:38 +00:00

Generic USB-RTC support

This commit is contained in:
Gyorgy Szombathelyi
2020-07-25 18:59:55 +02:00
parent 279b1a4187
commit 6b24b874ea
8 changed files with 60 additions and 19 deletions

View File

@@ -10,7 +10,7 @@ DUMP = $(BASE)-objdump
TODAY = `date +"%m/%d/%y"`
PRJ = firmware
SRC = Cstartup_SAM7.c fat.c fdd.c firmware.c fpga.c hardware.c spi.c hdd.c main.c menu.c mmc.c osd.c state.c syscalls.c user_io.c data_io.c boot.c rafile.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c mist_cfg.c archie.c arc_file.c font.c
SRC = Cstartup_SAM7.c fat.c fdd.c firmware.c fpga.c hardware.c spi.c hdd.c main.c menu.c mmc.c osd.c state.c syscalls.c user_io.c data_io.c boot.c rafile.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c mist_cfg.c archie.c arc_file.c font.c utils.c
SRC += usb/max3421e.c usb/usb.c usb/hub.c usb/hid.c usb/hidparser.c usb/timer.c usb/asix.c usb/pl2303.c usb/usbrtc.c usb/joymapping.c
# SRC += usb/storage.c
SRC += cdc_enumerate.c cdc_control.c

2
fpga.c
View File

@@ -983,7 +983,7 @@ void fpga_init(char *name) {
ChangeDirectory(OldDirectory);
} // end of minimig setup
if((user_io_core_type() == CORE_TYPE_MIST) || (user_io_core_type() == CORE_TYPE_MIST2)) {
puts("Running mist setup");

11
ikbd.c
View File

@@ -32,6 +32,7 @@
#include "ikbd.h"
#include "debug.h"
#include "usb.h"
#include "utils.h"
#define IKBD_AUTO_MS 20
@@ -81,7 +82,7 @@ static struct {
} mouse;
// ----- clock state ------
unsigned char date[6];
unsigned char date[7];
unsigned int tx_cnt; // tx byte counter for debugging
@@ -125,14 +126,6 @@ static void enqueue(unsigned short b) {
wptr = (wptr+1)&(QUEUE_LEN-1);
}
unsigned char bcd2bin(unsigned char in) {
return 10*(in >> 4) + (in & 0x0f);
}
unsigned char bin2bcd(unsigned char in) {
return 16*(in/10) + (in % 10);
}
// convert internal joystick format into atari ikbd format
static unsigned char joystick_map2ikbd(unsigned char in) {
unsigned char out = 0;

View File

@@ -10,6 +10,7 @@
#include "debug.h"
#include "usb.h"
#include "usbrtc.h"
#include "utils.h"
#define I2C_M_RD 0x01
@@ -195,14 +196,6 @@ static uint8_t usb_rtc_release(usb_device_t *dev) {
return 0;
}
static uint8_t bcd2bin(uint8_t in) {
return 10*(in >> 4) + (in & 0x0f);
}
static uint8_t bin2bcd(int8_t in) {
return 16*(in/10) + (in % 10);
}
uint8_t usb_rtc_get_time(uint8_t *d) {
uint8_t i;
usb_device_t *devs = usb_get_devices(), *dev = NULL;
@@ -230,6 +223,7 @@ uint8_t usb_rtc_get_time(uint8_t *d) {
d[3] = bcd2bin(time.hour_bcd);
d[4] = bcd2bin(time.min_bcd);
d[5] = bcd2bin(time.sec_bcd);
d[6] = time.day;
return 1;
}
@@ -255,6 +249,7 @@ uint8_t usb_rtc_set_time(uint8_t *d) {
time.hour_bcd = bin2bcd(d[3]);
time.min_bcd = bin2bcd(d[4]);
time.sec_bcd = bin2bcd(d[5]);
time.day = d[3];
if(!i2c_write_cmd_and_data(dev, DS1307_ADDR, 0, &time, sizeof(struct timeS))) {
usbrtc_debugf("Error writing time");

View File

@@ -22,6 +22,7 @@
#include "tos.h"
#include "errors.h"
#include "arc_file.h"
#include "utils.h"
// up to 16 key can be remapped
#define MAX_REMAP 16
@@ -80,6 +81,9 @@ bool caps_status = 0;
bool num_status = 0;
bool scrl_status = 0;
#define RTC_FREQ 1000 // 1 s
static unsigned long rtc_timer;
#define VIDEO_KEEP_VALUE 0x87654321
#define video_keep (*(int*)0x0020FF10)
#define video_altered (*(uint8_t*)0x0020FF14)
@@ -227,6 +231,26 @@ void user_io_send_core_mod() {
spi_uio_cmd8(UIO_SET_MOD, core_mod);
}
void user_io_send_rtc(void) {
uint8_t date[7]; //year,month,date,hour,min,sec,day
uint8_t i;
if (usb_rtc_get_time((uint8_t*)&date)) {
//iprintf("Sending time of day %u:%02u:%02u %u.%u.%u\n",
// date[3], date[4], date[5], date[2], date[1], 1900 + date[0]);
spi_uio_cmd_cont(UIO_SET_RTC);
spi8(bin2bcd(date[5])); // sec
spi8(bin2bcd(date[4])); // min
spi8(bin2bcd(date[3])); // hour
spi8(bin2bcd(date[2])); // date
spi8(bin2bcd(date[1])); // month
spi8(bin2bcd(date[0]-100)); // year
spi8(bin2bcd(date[6])-1); //day 1-7 -> 0-6
spi8(0x40); // flag
DisableIO();
}
}
extern unsigned long iCurrentDirectory; // cluster number of current directory, 0 for root
void user_io_detect_core_type() {
@@ -1290,6 +1314,18 @@ void user_io_poll() {
if(core_type == CORE_TYPE_ARCHIE)
archie_poll();
if((core_type == CORE_TYPE_MINIMIG2) ||
(core_type == CORE_TYPE_MIST2) ||
(core_type == CORE_TYPE_ARCHIE) ||
(core_type == CORE_TYPE_8BIT))
{
if(CheckTimer(rtc_timer))
{
rtc_timer = GetTimer(RTC_FREQ);
user_io_send_rtc();
}
}
if(CheckTimer(led_timer))
{
led_timer = GetTimer(LED_FREQ);

View File

@@ -54,6 +54,7 @@
#define UIO_GET_KBD_LED 0x1f // keyboard LEDs control
#define UIO_SIO_OUT 0x20 // serial out
#define UIO_SET_MOD 0x21 // send core variant from metadata (ARC) file
#define UIO_SET_RTC 0x22 // send real-time-clock data
// extended joystick control (32 bit value)
#define UIO_JOYSTICK0_EXT 0x60

9
utils.c Normal file
View File

@@ -0,0 +1,9 @@
#include "utils.h"
unsigned char bin2bcd(unsigned char in) {
return 16*(in/10) + (in % 10);
}
unsigned char bcd2bin(unsigned char in) {
return 10*(in >> 4) + (in & 0x0f);
}

7
utils.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef _UTILS_H_
#define _UTILS_H_
unsigned char bin2bcd(unsigned char in);
unsigned char bcd2bin(unsigned char in);
#endif