@@ -112,6 +112,10 @@ typedef enum {
112112
113113 TASK_READ_SECTOR ,
114114
115+ TASK_WRITE_CONFIG ,
116+ TASK_READ_CONFIG ,
117+ TASK_CLEAR_CONFIG ,
118+
115119 TASK_WAIT_FLASH_BUSY ,
116120} steami_task ;
117121
@@ -205,6 +209,40 @@ static void on_I2C_receive_command(steami_i2c_command cmd, uint8_t* rx, uint16_t
205209 break ;
206210 }
207211
212+ case WRITE_CONFIG :{
213+ if (is_busy ()){
214+ steami_uart_write_string ("ERROR I2C busy.\n" );
215+ break ;
216+ }
217+ if (rx_len < 3 ){
218+ error_status_bad_parameter (& status_error );
219+ break ;
220+ }
221+ current_task = TASK_WRITE_CONFIG ;
222+ memcpy (task_rx , rx , rx_len );
223+ task_rx_len = rx_len ;
224+ break ;
225+ }
226+
227+ case READ_CONFIG :{
228+ if (is_busy ()){
229+ steami_uart_write_string ("ERROR I2C busy.\n" );
230+ break ;
231+ }
232+ current_task = TASK_READ_CONFIG ;
233+ memcpy (task_rx , rx , rx_len );
234+ task_rx_len = rx_len ;
235+ break ;
236+ }
237+
238+ case CLEAR_CONFIG :
239+ if (is_busy ()){
240+ steami_uart_write_string ("ERROR I2C busy.\n" );
241+ break ;
242+ }
243+ current_task = TASK_CLEAR_CONFIG ;
244+ break ;
245+
208246 case STATUS :{
209247 uint8_t status = 0x00 ;
210248
@@ -394,6 +432,65 @@ void process_task()
394432 }
395433
396434
435+ case TASK_WRITE_CONFIG :{
436+ if ( steami_flash_is_busy () ){
437+ break ;
438+ }
439+ // task_rx: [offset_hi, offset_lo, len, data...]
440+ if ( task_rx_len >= 3 ){
441+ uint16_t offset = ((uint16_t )task_rx [0 ] << 8 ) | task_rx [1 ];
442+ uint16_t len = task_rx [2 ];
443+ if ( len <= task_rx_len - 3 && steami_flash_write_config (offset , task_rx + 3 , len ) ){
444+ steami_uart_write_string ("Config written.\n" );
445+ }
446+ else {
447+ error_status_set_last_command_fail (& status_error );
448+ steami_uart_write_string ("ERROR Unable to write config.\n" );
449+ }
450+ }
451+ else {
452+ error_status_bad_parameter (& status_error );
453+ }
454+ current_task = TASK_WAIT_FLASH_BUSY ;
455+ break ;
456+ }
457+
458+ case TASK_READ_CONFIG :{
459+ if ( steami_flash_is_busy () ){
460+ break ;
461+ }
462+ if ( task_rx_len == 2 ){
463+ uint16_t offset = ((uint16_t )task_rx [0 ] << 8 ) | task_rx [1 ];
464+ if ( steami_flash_read_config (offset , buffer_sector , STEAMI_FLASH_SECTOR ) ){
465+ steami_i2c_set_tx_data (buffer_sector , STEAMI_FLASH_SECTOR );
466+ }
467+ else {
468+ error_status_set_last_command_fail (& status_error );
469+ steami_uart_write_string ("ERROR Unable to read config.\n" );
470+ }
471+ }
472+ else {
473+ error_status_bad_parameter (& status_error );
474+ }
475+ current_task = TASK_WAIT_FLASH_BUSY ;
476+ break ;
477+ }
478+
479+ case TASK_CLEAR_CONFIG :{
480+ if ( steami_flash_is_busy () ){
481+ break ;
482+ }
483+ if ( steami_flash_erase_config () ){
484+ steami_uart_write_string ("Config erased.\n" );
485+ }
486+ else {
487+ error_status_set_last_command_fail (& status_error );
488+ steami_uart_write_string ("ERROR Unable to erase config.\n" );
489+ }
490+ current_task = TASK_WAIT_FLASH_BUSY ;
491+ break ;
492+ }
493+
397494 case TASK_WAIT_FLASH_BUSY :
398495 if ( !steami_flash_is_busy () ){
399496 current_task = TASK_NONE ;
0 commit comments