Skip to content

Commit

Permalink
Add initial DIO setting (#90)
Browse files Browse the repository at this point in the history
* Add initial DIO setting
* Allow lowercase hex value
  • Loading branch information
at-wat authored Aug 20, 2020
1 parent f8c0311 commit f97a65f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tfrog-motordriver/communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ int hextoi(char* buf)
ret *= 16;
ret += *buf - 'A' + 0xA;
}
else if ('a' <= *buf && *buf <= 'f')
{
ret *= 16;
ret += *buf - 'a' + 0xA;
}
buf++;
}
return ret;
Expand Down Expand Up @@ -1033,6 +1038,12 @@ int extended_command_analyze(char* data)
send("BUZ_LVL");
itoa10(val, saved_param.buz_lvl);
send(val);
send("; \nINITIODIR:");
nhex(val, saved_param.io_dir, 2);
send(val);
send("; \nINITIODATA:");
nhex(val, saved_param.io_data, 2);
send(val);
send("; \n\n");
}
else if (strstr(data, "$LOCKPARAM") == data)
Expand Down Expand Up @@ -1237,6 +1248,20 @@ int extended_command_analyze(char* data)
send(data);
send("\n00P\n\n");
}
else if (strstr(data, "$SETINITIODIR") == data)
{
saved_param.io_dir = hextoi(data + 13);

send(data);
send("\n00P\n\n");
}
else if (strstr(data, "$SETINITIODATA") == data)
{
saved_param.io_data = hextoi(data + 14);

send(data);
send("\n00P\n\n");
}
else if (strstr(data, "$EEPROMSAVE") == data)
{
if (EEPROM_Write(0, &saved_param, sizeof(saved_param)) < 0)
Expand Down
4 changes: 4 additions & 0 deletions tfrog-motordriver/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct _Tfrog_EEPROM_data
unsigned char buz_lvl;
unsigned char high_frequency_encoder;
unsigned char rely_hall;
unsigned char io_dir;
unsigned char io_data;
char __endbyte; // must be at the end of the struct to detect actual struct size
} Tfrog_EEPROM_data;

Expand Down Expand Up @@ -64,6 +66,8 @@ typedef struct _Tfrog_EEPROM_data
0, \
0, \
0, \
0, \
0, \
}

#define TFROG_EEPROM_DATA_TEXT 0
Expand Down
4 changes: 4 additions & 0 deletions tfrog-motordriver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ int main()
{
THEVA.GENERAL.ENCODER.HFREQ = 0;
}

driver_state.io_dir = saved_param.io_dir;
set_io_dir(saved_param.io_dir);
set_io_data(saved_param.io_data);
}

// Configure USB vbus pin
Expand Down

0 comments on commit f97a65f

Please sign in to comment.