From 15ac85b50c4aa6d32966cfeec5bc650c037aa0c1 Mon Sep 17 00:00:00 2001 From: jede Date: Wed, 14 Dec 2016 23:45:20 +0100 Subject: [PATCH] Adding ch376.h header, correcting some bugs --- include/ch376.h | 55 ++++++++++++++++++++++++++++++++++++++++ libsrc/telemon30/ch376.s | 8 +++--- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 include/ch376.h diff --git a/include/ch376.h b/include/ch376.h new file mode 100644 index 000000000..9db801eaf --- /dev/null +++ b/include/ch376.h @@ -0,0 +1,55 @@ + + +/* /// "Portable types" */ + + + + +/* /// "CH376 interface commands and constants" */ + +// Chip version +#define CH376_DATA_IC_VER 3 + +// Commands +#define CH376_CMD_NONE 0x00 +#define CH376_CMD_GET_IC_VER 0x01 +#define CH376_CMD_CHECK_EXIST 0x06 +#define CH376_CMD_SET_USB_MODE 0x15 +#define CH376_CMD_GET_STATUS 0x22 +#define CH376_CMD_RD_USB_DATA0 0x27 +#define CH376_CMD_WR_REQ_DATA 0x2d +#define CH376_CMD_SET_FILE_NAME 0x2f +#define CH376_CMD_DISK_MOUNT 0x31 +#define CH376_CMD_FILE_OPEN 0x32 +#define CH376_CMD_FILE_ENUM_GO 0x33 +#define CH376_CMD_FILE_CREATE 0x34 +#define CH376_CMD_FILE_CLOSE 0x36 +#define CH376_CMD_BYTE_LOCATE 0x39 +#define CH376_CMD_BYTE_READ 0x3a +#define CH376_CMD_BYTE_RD_GO 0x3b +#define CH376_CMD_BYTE_WRITE 0x3c +#define CH376_CMD_BYTE_WR_GO 0x3d +#define CH376_CMD_DISK_QUERY 0x3f +#define CH376_CMD_DISK_RD_GO 0x55 + +#define CH376_ARG_SET_USB_MODE_INVALID 0x00 +#define CH376_ARG_SET_USB_MODE_SD_HOST 0x03 +#define CH376_ARG_SET_USB_MODE_USB_HOST 0x06 + +// Status & errors +#define CH376_ERR_OPEN_DIR 0x41 +#define CH376_ERR_MISS_FILE 0x42 + +#define CH376_RET_SUCCESS 0x51 +#define CH376_RET_ABORT 0x5f + +#define CH376_INT_SUCCESS 0x14 +#define CH376_INT_DISK_READ 0x1d +#define CH376_INT_DISK_WRITE 0x1e + + +unsigned char ch376_check_exist(unsigned char value); +unsigned char ch376_ic_get_version(void); +void ch376_set_usb_mode(unsigned char value); +unsigned char ch376_disk_mount(void); + diff --git a/libsrc/telemon30/ch376.s b/libsrc/telemon30/ch376.s index 1b75c2b18..90e2878e1 100644 --- a/libsrc/telemon30/ch376.s +++ b/libsrc/telemon30/ch376.s @@ -4,7 +4,7 @@ .export _ch376_reset .export _ch376_check_exist .export _ch376_disk_mount - + .export _ch376_set_usb_mode .import popax .importzp sp,tmp2,tmp3,tmp1 .include "telemon30.inc" @@ -123,6 +123,7 @@ loop: .proc _ch376_ic_get_version lda #CH376_GET_IC_VER sta CH376_COMMAND + ldx #0 lda CH376_DATA rts .endproc @@ -131,10 +132,10 @@ loop: .proc _ch376_set_usb_mode ; CH376_SET_USB_MODE_CODE_USB_HOST_SOF_PACKAGE_AUTOMATICALLY - sta tmp1 + pha lda #CH376_SET_USB_MODE ; $15 sta CH376_COMMAND - lda tmp1 + pla sta CH376_DATA rts .endproc @@ -169,6 +170,7 @@ loop: sta CH376_COMMAND jsr _ch376_wait_response ; if we read data value, we have then length of the volume name + ldx #0 rts .endproc -- 2.39.5