Skip to content

Commit

Permalink
Merge pull request #36 from djuseeq/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
djuseeq authored Sep 29, 2020
2 parents b7b19a5 + 20a81a7 commit b280b18
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 87 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Configure the jumpers on the module depending on which communication protocol yo

### PCB modding for SD card
> If you planning to use the chip for SD card also and you have a pcb like on the photo above, then some soldering skill is required.
> First of all with a DMM check the pins of the chip(26,25,23 and 7) are theye floating or connected to GND/VCC.
> First of all with a DMM check the pins of the chip(26,25,23 and 7) are they floating or connected to GND/VCC.
> On mine pcb the chip pin 23 (SD_CS) is connected to ground, like you can [see here](extras/schematic.png),
> pins or the chip have incorrect marking(looks like CH375 which one doesn't support SD card) . [Link](https://www.mpja.com/download/31813MPSch.pdf) for the module's schematic diagram.
> I used soldering iron and tweezer to lift up the pin from the pcb(be careful, you can easily break the chip's leg).
Expand All @@ -27,6 +27,11 @@ Configure the jumpers on the module depending on which communication protocol yo
> Here are some photos from the ugly modding ;) [Photo1](extras/board1.jpg) [Photo2](extras/board2.jpg).
## Versions
v1.4.4 Sep 29, 2020
- error handling improvement
- new function, getChipVer()
- bug fix, issue #34 Variable Naming conflicts with core ESP32 Variables

v1.4.3 Feb 06, 2020
- bug fix issue #22 unknown partition
- new functions as requested in #21 , #23
Expand Down Expand Up @@ -198,6 +203,7 @@ v1.1 Feb 25, 2019
getFileAttrb();// returns byte value, see /src/CommDef.h , (File attributes)
getCursorPos();// returns unsigned long value
getEOF();// returns boolean value, true EOF is reached
getChipVer();// returns byte value, returns the CH chip firmware version number
```
## Tested boards
|Board(arch) | SPI | HW Serial | SW Serial|
Expand Down
18 changes: 8 additions & 10 deletions examples/basicUsageHwSerial/basicUsageHwSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void loop() {
case 55: //7
printInfo("COMMAND7: List directory"); //Print all file names in the current directory
while(flashDrive.listDir()){ // reading next file
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){//directory
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){//directory
Serial.print('/');
Serial.println(flashDrive.getFileName()); // get the actual file name
} else {
Expand Down Expand Up @@ -197,7 +197,7 @@ void loop() {
//*****************************************************************************************************************************************************
case 57: //9
switch(flashDrive.cd("/DIR1/DIR2/DIR3",1)){
case ERR_LONGFILENAME: //0x01
case CH376_ERR_LONGFILENAME: //0x01
Serial.println(F("Directory name is too long"));
break;

Expand Down Expand Up @@ -235,14 +235,12 @@ void loop() {
}//end loop

//Print information
void printInfo(char info[]){
char * infoPtr = info;
int infoLength = 0;
while(*infoPtr){
infoPtr++;
infoLength++;
if(infoLength > 40) break;
}
void printInfo(const char info[]){

int infoLength = strlen(info);
if(infoLength > 40){
infoLength = 40;
}
Serial.print(F("\n\n"));
for(int a = 0; a < infoLength; a++){
Serial.print('*');
Expand Down
18 changes: 8 additions & 10 deletions examples/basicUsageSPI/basicUsageSPI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void loop() {
case 55: //7
printInfo("COMMAND7: List directory"); //Print all file names in the current directory
while(flashDrive.listDir()){ // reading next file
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){//directory
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){//directory
Serial.print('/');
Serial.println(flashDrive.getFileName()); // get the actual file name
} else {
Expand Down Expand Up @@ -203,7 +203,7 @@ void loop() {
//*****************************************************************************************************************************************************
case 57: //9
switch(flashDrive.cd("/DIR1/DIR2/DIR3",1)){
case ERR_LONGFILENAME: //0x01
case CH376_ERR_LONGFILENAME: //0x01
Serial.println(F("Directory name is too long"));
break;

Expand Down Expand Up @@ -241,14 +241,12 @@ void loop() {
}//end loop

//Print information
void printInfo(char info[]){
char * infoPtr = info;
int infoLength = 0;
while(*infoPtr){
infoPtr++;
infoLength++;
if(infoLength > 40) break;
}
void printInfo(const char info[]){

int infoLength = strlen(info);
if(infoLength > 40){
infoLength = 40;
}
Serial.print(F("\n\n"));
for(int a = 0; a < infoLength; a++){
Serial.print('*');
Expand Down
18 changes: 8 additions & 10 deletions examples/basicUsageSPI_USB_SD/basicUsageSPI_USB_SD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void loop() {
case 55: //7
printInfo("COMMAND7: List directory"); //Print all file names in the current directory
while(flashDrive.listDir()){ // reading next file
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){//directory
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){//directory
Serial.print('/');
Serial.println(flashDrive.getFileName()); // get the actual file name
} else {
Expand Down Expand Up @@ -211,7 +211,7 @@ void loop() {
//*****************************************************************************************************************************************************
case 57: //9
switch(flashDrive.cd("/DIR1/DIR2/DIR3",1)){
case ERR_LONGFILENAME: //0x01
case CH376_ERR_LONGFILENAME: //0x01
Serial.println(F("Directory name is too long"));
break;

Expand Down Expand Up @@ -249,14 +249,12 @@ void loop() {
}//end loop

//Print information
void printInfo(char info[]){
char * infoPtr = info;
int infoLength = 0;
while(*infoPtr){
infoPtr++;
infoLength++;
if(infoLength > 40) break;
}
void printInfo(const char info[]){

int infoLength = strlen(info);
if(infoLength > 40){
infoLength = 40;
}
Serial.print(F("\n\n"));
for(int a = 0; a < infoLength; a++){
Serial.print('*');
Expand Down
18 changes: 8 additions & 10 deletions examples/basicUsageSoftSerial/basicUsageSoftSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void loop() {
case 55: //7
printInfo("COMMAND7: List directory"); //Print all file names in the current directory
while(flashDrive.listDir()){ // reading next file
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){//directory
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){//directory
Serial.print('/');
Serial.println(flashDrive.getFileName()); // get the actual file name
} else {
Expand Down Expand Up @@ -200,7 +200,7 @@ void loop() {
//*****************************************************************************************************************************************************
case 57: //9
switch(flashDrive.cd("/DIR1/DIR2/DIR3",1)){
case ERR_LONGFILENAME: //0x01
case CH376_ERR_LONGFILENAME: //0x01
Serial.println(F("Directory name is too long"));
break;

Expand Down Expand Up @@ -238,14 +238,12 @@ void loop() {
}//end loop

//Print information
void printInfo(char info[]){
char * infoPtr = info;
int infoLength = 0;
while(*infoPtr){
infoPtr++;
infoLength++;
if(infoLength > 40) break;
}
void printInfo(const char info[]){

int infoLength = strlen(info);
if(infoLength > 40){
infoLength = 40;
}
Serial.print(F("\n\n"));
for(int a = 0; a < infoLength; a++){
Serial.print('*');
Expand Down
4 changes: 2 additions & 2 deletions examples/lcd_menu/lcd_menu.ino
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void menu(int fileCount){
if(!filePos) break;
filePos--;
}
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){// if the selected item is directory the do nothing
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){// if the selected item is directory the do nothing
b_exit = true;// done with menu function
} else {// if the selected item is a valid file then print it to serial
flashDrive.setFileName();
Expand All @@ -129,7 +129,7 @@ void fileListToLCD(byte a) {
for (byte i=0; i<LCD_ROW; i++){
lcd.setCursor(1, i);
if(flashDrive.listDir()){
if(flashDrive.getFileAttrb() == ATTR_DIRECTORY){
if(flashDrive.getFileAttrb() == CH376_ATTR_DIRECTORY){
lcd.print('/');
}
lcd.print(flashDrive.getFileName());
Expand Down
2 changes: 1 addition & 1 deletion examples/readUntil/readUntil.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void setup() {
flashDrive.setFileName("TEST1.TXT"); //set the file name
flashDrive.openFile(); //open the file
//read data from flash drive until we reach EOF
while(flashDrive.getCursorPos() < flashDrive.getFileSize()){
while(!flashDrive.getEOF()){
readMore = true;
while(readMore){
// terminator character, temporary buffer where we read data from flash drive and the size of that buffer
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ getSource KEYWORD2
getError KEYWORD2
getCursorPos KEYWORD2
getEOF KEYWORD2
getChipVer KEYWORD2

setFileName KEYWORD2
setYear KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Ch376msc
version=1.4.3
version=1.4.4
author=György Kovács
maintainer=György Kovács <[email protected]>
sentence=A library for CH376 file manager control chip.
Expand Down
24 changes: 14 additions & 10 deletions src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint8_t Ch376msc::mount(){ // return ANSWSUCCESS or ANSW DISK DISCON
spiEndTransfer();
tmpReturn = spiWaitInterrupt();
}//end if interface
if(tmpReturn != ANSW_USB_INT_SUCCESS){
if(!_errorCode && tmpReturn != ANSW_USB_INT_SUCCESS){
setError(tmpReturn);
}
return tmpReturn;
Expand All @@ -67,7 +67,7 @@ uint8_t Ch376msc::fileEnumGo(){
spiEndTransfer();
tmpReturn = spiWaitInterrupt();
}
if((tmpReturn != ANSW_USB_INT_DISK_READ) && (tmpReturn != ANSW_ERR_MISS_FILE)){
if(!_errorCode && (tmpReturn != ANSW_USB_INT_DISK_READ) && (tmpReturn != ANSW_ERR_MISS_FILE)){
setError(tmpReturn);
}
return tmpReturn;
Expand All @@ -84,7 +84,7 @@ uint8_t Ch376msc::byteRdGo(){
spiEndTransfer();
tmpReturn = spiWaitInterrupt();
}
if((tmpReturn != ANSW_USB_INT_DISK_READ) && (tmpReturn != ANSW_USB_INT_SUCCESS)){
if(!_errorCode && (tmpReturn != ANSW_USB_INT_DISK_READ) && (tmpReturn != ANSW_USB_INT_SUCCESS)){
setError(tmpReturn);
}
return tmpReturn;
Expand Down Expand Up @@ -132,7 +132,7 @@ void Ch376msc::rdFatInfo(){
spiEndTransfer();
}
if(owrflow){
setError(ERR_OVERFLOW);
setError(CH376_ERR_OVERFLOW);
} else {
memcpy ( &_fileData, &fatInfBuffer, sizeof(fatInfBuffer) ); //copy raw data to structured variable
}
Expand All @@ -150,7 +150,7 @@ uint8_t Ch376msc::byteWrGo(){
spiEndTransfer();
tmpReturn = spiWaitInterrupt();
}
if((tmpReturn != ANSW_USB_INT_DISK_WRITE) && (tmpReturn != ANSW_USB_INT_SUCCESS)){
if(!_errorCode && (tmpReturn != ANSW_USB_INT_DISK_WRITE) && (tmpReturn != ANSW_USB_INT_SUCCESS)){
setError(tmpReturn);
}
return tmpReturn;
Expand All @@ -172,7 +172,7 @@ uint8_t Ch376msc::reqByteRead(uint8_t a){
spiEndTransfer();
tmpReturn= spiWaitInterrupt();
}
if((tmpReturn != ANSW_USB_INT_SUCCESS) && (tmpReturn != ANSW_USB_INT_DISK_READ)){
if(!_errorCode && (tmpReturn != ANSW_USB_INT_SUCCESS) && (tmpReturn != ANSW_USB_INT_DISK_READ)){
setError(tmpReturn);
}
return tmpReturn;
Expand All @@ -194,7 +194,7 @@ uint8_t Ch376msc::reqByteWrite(uint8_t a){
spiEndTransfer();
tmpReturn = spiWaitInterrupt();
}
if((tmpReturn != ANSW_USB_INT_SUCCESS) && (tmpReturn != ANSW_USB_INT_DISK_WRITE)){
if(!_errorCode && (tmpReturn != ANSW_USB_INT_SUCCESS) && (tmpReturn != ANSW_USB_INT_DISK_WRITE)){
setError(tmpReturn);
}
return tmpReturn;
Expand Down Expand Up @@ -240,7 +240,9 @@ void Ch376msc::rdDiskInfo(){
}//end if success
}//end if UART
if(tmpReturn != ANSW_USB_INT_SUCCESS){// unknown partition issue #22
setError(tmpReturn);
if(!_errorCode){
setError(tmpReturn);
}//end if error
} else {
clearError();
_deviceAttached = true;
Expand Down Expand Up @@ -274,13 +276,15 @@ void Ch376msc::driveAttach(){
tmpReturn = spiWaitInterrupt();
}//end if interface
}//end if usb
if((tmpReturn == ANSW_USB_INT_CONNECT) || (!tmpReturn)){
for(uint8_t a = 0;a < 5;a++){
if(tmpReturn == ANSW_USB_INT_CONNECT){// TODO: itt figyelni
for(uint8_t a = 0;a < 5;a++){//try to mount, delay in worst case ~(number of attempts * ANSWTIMEOUT ms)
tmpReturn = mount();
if(tmpReturn == ANSW_USB_INT_SUCCESS){
clearError();
_deviceAttached = true;
break;
} else if(_errorCode != CH376_ERR_TIMEOUT){
break;
}//end if Success
}//end for
} else driveDetach();
Expand Down
10 changes: 5 additions & 5 deletions src/Ch376msc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ uint8_t Ch376msc::pingDevice(){
spiEndTransfer();
}
if(!tmpReturn){
setError(ERR_NO_RESPONSE);
setError(CH376_ERR_NO_RESPONSE);
}
return tmpReturn;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ uint8_t Ch376msc::listDir(const char* filename){
uint32_t tmOutCnt = millis();

while(!doneFiles){
if(millis() - tmOutCnt >= ANSWTIMEOUT) setError(ERR_TIMEOUT);
if(millis() - tmOutCnt >= ANSWTIMEOUT) setError(CH376_ERR_TIMEOUT);
if(!_deviceAttached){
moreFiles = false;
break;
Expand Down Expand Up @@ -341,9 +341,9 @@ uint8_t Ch376msc::cd(const char* dirPath, bool mkDir){
setFileName("/");
tmpReturn = openFile();
char* command = strtok(input, "/");//split path into tokens
while (command != NULL){
while (command != NULL && !_errorCode){
if(strlen(command) > 8){//if a dir name is longer than 8 char
tmpReturn = ERR_LONGFILENAME;
tmpReturn = CH376_ERR_LONGFILENAME;
break;
}
setFileName(command);
Expand All @@ -360,7 +360,7 @@ uint8_t Ch376msc::cd(const char* dirPath, bool mkDir){
command = strtok (NULL, "/");
}
} else {
tmpReturn = ERR_LONGFILENAME;
tmpReturn = CH376_ERR_LONGFILENAME;
}//end if path is to long
return tmpReturn;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Ch376msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
******************************************************
* Versions: *
* ****************************************************
* v1.4.4 Sep 29, 2020
* - error handling improvement
* - new function, getChipVer()
* - bug fix, issue #34 Variable Naming conflicts with core ESP32 Variables
*
* v1.4.3 Feb 06, 2020
* - bug fix issue #22 unknown partition
* - new functions as requested in #21 , #23
Expand Down Expand Up @@ -114,7 +119,6 @@ class Ch376msc {
uint8_t listDir(const char* filename = "*");
uint8_t readFile(char* buffer, uint8_t b_size);
uint8_t readRaw(uint8_t* buffer, uint8_t b_size);
//uint32_t readNextInt(char trmChar = '\n');
int32_t readLong(char trmChar = '\n');
uint32_t readULong(char trmChar = '\n');
double readDouble(char trmChar = '\n');
Expand Down Expand Up @@ -159,6 +163,7 @@ class Ch376msc {
uint8_t getFileAttrb();
uint8_t getSource();
uint8_t getError();
uint8_t getChipVer();
char* getFileName();
char* getFileSizeStr();
bool getDeviceStatus(); // usb device mounted, unmounted
Expand Down
Loading

0 comments on commit b280b18

Please sign in to comment.