# HG changeset patch # User David Douard # Date 1541456317 -3600 # Node ID 9ffa9d727d8096cf9a0ea84c1fe41732116d270f # Parent b4658776abb674ab6dc9c7e5ba6b3aaf346440a3 wip diff -r b4658776abb6 -r 9ffa9d727d80 .gitignore --- a/.gitignore Tue Dec 05 00:59:57 2017 +0100 +++ b/.gitignore Mon Nov 05 23:18:37 2018 +0100 @@ -1,1 +1,3 @@ -.pioenvs \ No newline at end of file +.pioenvs +.piolibdeps +.vscode/c_cpp_properties.json diff -r b4658776abb6 -r 9ffa9d727d80 .hgignore --- a/.hgignore Tue Dec 05 00:59:57 2017 +0100 +++ b/.hgignore Mon Nov 05 23:18:37 2018 +0100 @@ -1,2 +1,3 @@ .pioenvs .piolibdeps +misc diff -r b4658776abb6 -r 9ffa9d727d80 platformio.ini --- a/platformio.ini Tue Dec 05 00:59:57 2017 +0100 +++ b/platformio.ini Mon Nov 05 23:18:37 2018 +0100 @@ -21,17 +21,19 @@ platform = ststm32 framework = mbed board = nucleo_f446re -upload_port = /media/sdb -build_flags = -DHAVE_PC -lib_compat_mode = 0 +#upload_port = /media/sdb +#build_flags = -DHAVE_PC --verbose +#lib_compat_mode = 0 +build_flags = -DHAVE_PC -DPIO_FRAMEWORK_MBED_RTOS_PRESENT [env:l432kc] platform = ststm32 framework = mbed board = nucleo_l432kc -upload_port = /media/sdb -lib_compat_mode = 0 -build_flags = -DHAVE_PC +#upload_port = /media/sdb +#lib_compat_mode = 0 +#build_flags = -DHAVE_PC +build_flags = -DHAVE_PC -DPIO_FRAMEWORK_MBED_RTOS_PRESENT # [env:nucleo_f031k6] # platform = ststm31 diff -r b4658776abb6 -r 9ffa9d727d80 src/hp34comm.cpp --- a/src/hp34comm.cpp Tue Dec 05 00:59:57 2017 +0100 +++ b/src/hp34comm.cpp Mon Nov 05 23:18:37 2018 +0100 @@ -10,24 +10,15 @@ #endif -DigitalOut lled(LED1); +DigitalOut lled(LED3); #define RXTIMEOUT 0.05 #define STARTUPRETRY 0.5 + const uint8_t startup_seq[] = { 0x33, - 0x01, - 0x01, - 0x40, - // 0x02, -}; - -const uint8_t startup_seq2[] = { - 0x33, 0x02, 0x00, - 0x00, - // 0x02, }; HPSerial::statemethod HPSerial::state_table[NUM_STATES] = { @@ -44,16 +35,13 @@ cur_gstate(GSTATE_IDLE), ncmd(0) { - serial.baud(187500); + serial.baud(187500); cur_state = STATE_IDLE; serial.attach(callback(this, &HPSerial::rxIrq), Serial::RxIrq); } void HPSerial::startup(void) { - if (cur_gstate != GSTATE_STARTING) { - //_startup(); - cur_gstate = GSTATE_STARTING; - } + cur_gstate = GSTATE_STARTING; set_timer(0.002); // launch the startup in 10ms } @@ -68,17 +56,6 @@ cur_state = do_state_sending(); } -void HPSerial::_startup2(void) -{ - cur_gstate = GSTATE_STARTING2; - tr_data.size = sizeof(startup_seq2); - tr_data.cmd = 0xFF; - tr_data.pos = 0; - for(uint8_t i=0; i @@ -111,7 +88,7 @@ } unsigned int HPSerial::nerrors(uint8_t errorno) -{ +{ return errs[errorno]; } @@ -171,7 +148,7 @@ if (c == 0x86) { // shutdown pushCmd(tr_data.cmd, tr_data.size, tr_data.payload); return HPSerial::STATE_IDLE; - } + } return STATE_PAYLOAD_SIZE; } @@ -198,15 +175,15 @@ { // ghee if (c == 0xFF) - { - tr_data.pos--; - tr_data.payload[tr_data.pos] += 1; - } + { // resend current char + tr_data.pos--; + tr_data.payload[tr_data.pos] += 1; + } // TODO: check ACK values (c is the received ack) if (tr_data.pos >= tr_data.size) - { - return do_state_eot(); - } + { + return do_state_eot(); + } serial.putc(tr_data.payload[tr_data.pos++]); set_timer(RXTIMEOUT); return HPSerial::STATE_SENDING; @@ -214,15 +191,9 @@ HPSerial::state_t HPSerial::do_state_eot(uint8_t c) { - serial.putc(0x55); // EoT - if (cur_gstate == GSTATE_STARTING) { - cur_gstate = GSTATE_STARTING2; - set_timer(0.002); // launch startup2 in 10ms - } - else { - cur_gstate = GSTATE_IDLE; - set_timer(); // We are IDLE, detach the timeouter - } + serial.putc(0x55); // EoT + cur_gstate = GSTATE_IDLE; + set_timer(); // We are IDLE, detach the timeouter return STATE_IDLE; } @@ -234,15 +205,16 @@ void HPSerial::rxIrq(void) { uint8_t val; - if(serial.readable()) { // no reason why we would end here without - // this condition, but hey + if(serial.readable()) + { // no reason why we would end here without + // this condition, but hey #ifdef DEBUG2 inrx=1; #endif - lled = 1; + //lled = 1; val = serial.getc(); cur_state = run_state(cur_state, val); - lled = 0; + //lled = 0; #ifdef DEBUG2 inrx=0; #endif @@ -254,13 +226,9 @@ set_timer(); // detach the timeouter if (cur_gstate == GSTATE_STARTING) _startup(); - else if (cur_gstate == GSTATE_STARTING2) - _startup2(); else // reset { cur_gstate = GSTATE_IDLE; cur_state = STATE_IDLE; } } - - diff -r b4658776abb6 -r 9ffa9d727d80 src/hp34comm.h --- a/src/hp34comm.h Tue Dec 05 00:59:57 2017 +0100 +++ b/src/hp34comm.h Mon Nov 05 23:18:37 2018 +0100 @@ -22,18 +22,18 @@ char value[MAX_BUFF+1]; unsigned long id; } CMD; - + HPSerial(PinName tx, PinName rx); bool cmd_available(void); bool pop(CMD& cmd); bool cmd_buf_full(void); unsigned int nerrors(uint8_t errorno); - + void startup(void); void send(const uint8_t *buf, uint8_t size); void sendkey(uint8_t keycode); - + private: void pushCmd(uint8_t cmd, uint8_t size, char *payload); void rxIrq(void); @@ -57,7 +57,6 @@ // global state machine typedef enum { GSTATE_STARTING, - GSTATE_STARTING2, GSTATE_IDLE, GSTATE_TX, GSTATE_RX, @@ -66,18 +65,18 @@ /* gstate_t do_start(); */ /* gstate_t do_send(); */ /* gstate_t do_receive(); */ - + /* typedef gstate_t(HPSerial::*gstatemethod)(); */ /* statemethod const gstate_table[NUM_GSTATES] = { */ /* &HPSerial::do_start, */ /* &HPSerial::do_send, */ /* &HPSerial::do_receive, */ /* }; */ - + /* gstate_t run_gstate(gstate_t cur_state); */ private: gstate_t cur_gstate; - + public: // transmission state machine typedef enum { @@ -89,7 +88,7 @@ STATE_EOT, NUM_STATES} state_t; state_t state() {return cur_state;}; - + private: typedef struct state_data { uint8_t cmd; @@ -99,7 +98,6 @@ } state_data_t; void _startup(void); - void _startup2(void); state_t do_state_initial(uint8_t c=0x00); state_t do_state_command(uint8_t c); state_t do_state_payload_size(uint8_t c); @@ -108,9 +106,9 @@ state_t do_state_eot(uint8_t c=0x00); void send_ack(uint8_t c); - + typedef state_t(HPSerial::*statemethod)(uint8_t c); - static statemethod state_table[NUM_STATES]; + static statemethod state_table[NUM_STATES]; state_t run_state(state_t cur_state, uint8_t c); state_t cur_state; diff -r b4658776abb6 -r 9ffa9d727d80 src/main.cpp --- a/src/main.cpp Tue Dec 05 00:59:57 2017 +0100 +++ b/src/main.cpp Mon Nov 05 23:18:37 2018 +0100 @@ -1,8 +1,8 @@ #include "stdio.h" -#include "mbed.h" -#include "rtos.h" -#include "string" +#include +#include +#include #include "Terminal6x8.h" #include "Mono19x27.h" @@ -61,12 +61,12 @@ // USBTX PA_2 // USBRX PA_3 // display -#define DSP_MOSI PB_15 +#define DSP_MOSI PB_15 // blue #define DSP_MISO NC -#define DSP_SCLK PB_13 -#define DSP_CS PB_12 -#define DSP_RST PB_5 -#define DSP_DC PB_4 +#define DSP_SCLK PB_13 // yellow +#define DSP_CS PB_12 // green +#define DSP_RST PB_5 // green +#define DSP_DC PB_4 // red // UART for RX (CPU->DP) #define HP_RX PC_11 // serial3 RX @@ -248,48 +248,48 @@ { // flag, zone, x0, y0, msg, icon // right-side icons area - { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.1 - { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.2 - - - { 0x03, 0x04, 1, 2, "Channel"}, // F1.4 + { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.0 + { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.1 + // F1.2 == Channel frame + { 0x03, 0x04, 1, 2, "Channel"}, // F1.3 + // F1.7 == Alarm frame // col 1 - { 0x34, 0x10, 0, 0, "MON"}, // F4.5 - { 0x33, 0x10, 0, 8, "VIEW"}, // F4.4 - { 0x35, 0x10, 0, 16, "SCAN"}, // F4.6 + { 0x34, 0x10, 0, 0, "MON"}, // F4.4 + { 0x33, 0x10, 0, 8, "VIEW"}, // F4.3 + { 0x35, 0x10, 0, 16, "SCAN"}, // F4.5 //col 2 - { 0x32, 0x20, 0, 0, "*"}, // F4.3 - { 0x36, 0x20, 0, 8, "CFG"}, // F4.7 - { 0x27, 0x20, 0, 16, "ERR"}, // F3.8 + { 0x32, 0x20, 0, 0, "*"}, // F4.2 + { 0x36, 0x20, 0, 8, "CFG"}, // F4.6 + { 0x27, 0x20, 0, 16, "ERR"}, // F3.7 // col 3 - { 0x41, 0x040, 0, 0, "ADRS"}, // F4.2 - { 0x40, 0x040, 0, 8, "RMT"}, // F4.1 + { 0x41, 0x040, 0, 0, "ADRS"}, // F4.1 + { 0x40, 0x040, 0, 8, "RMT"}, // F4.0 // col 4 - { 0x26, 0x080, 0, 0, "EXT"}, // F3.7 - { 0x25, 0x080, 0, 8, "ONCE"}, // F3.6 + { 0x26, 0x080, 0, 0, "EXT"}, // F3.6 + { 0x25, 0x080, 0, 8, "ONCE"}, // F3.5 - { 0xFF, 0x080, 0, 16, "MEM"}, + { 0x23, 0x080, 0, 16, "MEM"}, // F3.3 // col 5 - { 0x14, 0x100, 0, 0, "4W"}, // F2.5 - { 0x15, 0x100, 0, 8, "OC"}, // F2.6 - { 0xFF, 0x100, 0, 16, "LST"}, // F3.8? Nope - { 0xFF, 0x100, 0, 16, "MIN"}, - { 0xFF, 0x100, 0, 16, "MAX"}, - { 0xFF, 0x100, 0, 16, "AVG"}, + { 0x14, 0x100, 0, 0, "4W"}, // F2.4 + { 0x15, 0x100, 0, 8, "OC"}, // F2.5 + { 0x22, 0x100, 0, 16, "LST"}, // F3.2 + { 0x21, 0x100, 0, 16, "MIN"}, // F3.1 + { 0x20, 0x100, 0, 16, "MAX"}, // F3.0 + { 0x17, 0x100, 0, 16, "AVG"}, // F2.7 - { 0x05, 0x08, 0, 0, "Alarm"}, // F1.6 - { 0x06, 0x08, 0, 10, "H"}, // F1.7 - { 0x13, 0x08, 6, 10, "1"}, // F2.4 - { 0x10, 0x08, 12, 10, "2"}, // F2.1 - { 0x12, 0x08, 18, 10, "3"}, // F2.3 - { 0x11, 0x08, 24, 10, "4"}, // F2.2 - { 0x04, 0x08, 30, 10, "L"}, // F1.5 + { 0x05, 0x08, 0, 0, "Alarm"}, // F1.5 + { 0x06, 0x08, 0, 10, "H"}, // F1.6 + { 0x13, 0x08, 6, 10, "1"}, // F2.3 + { 0x10, 0x08, 12, 10, "2"}, // F2.0 + { 0x12, 0x08, 18, 10, "3"}, // F2.2 + { 0x11, 0x08, 24, 10, "4"}, // F2.1 + { 0x04, 0x08, 30, 10, "L"}, // F1.4 }; @@ -310,8 +310,8 @@ static const FRAME frames[] = { - { 0x02, 203, 35, 255, 54}, // F1.3 - channel frame - { 0x07, 160, 28, 202, 54}, // F1.8 - alarm frame + { 0x02, 203, 35, 255, 54}, // F1.2 - channel frame + { 0x07, 160, 28, 202, 54}, // F1.7 - alarm frame }; @@ -352,54 +352,54 @@ #ifdef HAVE_PC pc.baud (115200); #endif - + printf("\n\nSETUP\n"); printf(" System Core Clock = %.3f MHZ\r\n", (float)SystemCoreClock/1000000); - + //printf("Attaching Led 1: %d\n", LED1); //blinker.attach(callback(timeout_h), 0.5f); - + hp = NULL; - printf("Setup HP communication pins\n"); - printf(" HP_RX=%d\n", HP_RX); + printf("Setup HP communication pins\r\n"); + printf(" HP_RX=%d\r\n", HP_RX); DigitalIn(HP_RX).mode(PullDown); - printf(" HP_TX=%d\n", HP_TX); + printf(" HP_TX=%d\r\n", HP_TX); DigitalOut(HP_TX).write(1); - printf(" HP_RST=%d\n", HP_RST); + printf(" HP_RST=%d\r\n", HP_RST); DigitalIn(HP_RST).mode(PullDown); - - printf(" setup QEI pins\n"); - printf(" ENC1=%d\n", KP_ENC1); + + printf(" setup QEI pins\r\n"); + printf(" ENC1=%d\r\n", KP_ENC1); DigitalIn(KP_ENC1).mode(PullUp); - printf(" ENC2=%d\n", KP_ENC2); + printf(" ENC2=%d\r\n", KP_ENC2); DigitalIn(KP_ENC2).mode(PullUp); qenc.attach(&qei_cb); - printf(" setup Keypad\n"); + printf(" setup Keypad\r\n"); cur_keycode.keyevent = KEY_NONE; uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]); uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]); kpad = new Keypad(nrows, kp_in, ncols, kp_out); - printf(" attach Keypad callbacks\n"); + printf(" attach Keypad callbacks\r\n"); kpad->attach(&kp_cb, &kr_cb); - printf(" start Keypad\n"); - kpad->start(); - - printf("Setup OLED display\n"); + printf(" start Keypad\r\n"); + kpad->start(); + + printf("Setup OLED display\r\n"); splashscreen = true; // init the LCD - printf(" DSP_MOSI=%d\n", DSP_MOSI); - printf(" DSP_MISO=%d\n", DSP_MISO); - printf(" DSP_SCLK=%d\n", DSP_SCLK); - printf(" DSP_CS=%d\n", DSP_CS); - printf(" DSP_RST=%d\n", DSP_RST); - printf(" DSP_DC=%d\n", DSP_DC); + printf(" DSP_MOSI=%d\r\n", DSP_MOSI); + printf(" DSP_MISO=%d\r\n", DSP_MISO); + printf(" DSP_SCLK=%d\r\n", DSP_SCLK); + printf(" DSP_CS=%d\r\n", DSP_CS); + printf(" DSP_RST=%d\r\n", DSP_RST); + printf(" DSP_DC=%d\r\n", DSP_DC); dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, DSP_RST, DSP_DC, "SSD1322"); //dsp.set_orientation(3); - printf(" configure DSP\n"); + printf(" configure DSP\r\n"); // myLCD.set_font((unsigned char*) Terminal6x8); // myLCD.claim(stdout); // send stdout to the LCD display // myLCD.claim(stderr); // send stderr to the LCD display @@ -414,7 +414,7 @@ for (uint8_t i=0; ilocate(30, 10); dsp->set_font((unsigned char*)Mono19x27); dsp->printf("HP34970A"); @@ -423,39 +423,39 @@ dsp->printf("David Douard"); dsp->copy_to_lcd(); - printf("Starting LCD thread\n"); + printf("Starting LCD thread\r\n"); tdsp.start(©_to_lcd); - printf("Starting Event thread\n"); - tloop.start(&loop); - - printf("Attaching timers\n"); + //printf("Starting Event thread\r\n"); + //tloop.start(&loop); + + printf("Attaching timers\r\n"); splashscreen_timer.attach(callback(&end_splashscreen), 2); rst.fall(&reset_irq); - - printf("SETUP DONE\n"); + + printf("SETUP DONE\r\n"); } void end_splashscreen(void) { - printf("End of splash screen\n"); + printf("End of splash screen\r\n"); splashscreen = false; } void reset_irq(void) { - rst_delay.attach(callback(&reset), 0.1); + rst_delay.attach(callback(&reset), 0.1); } void reset(void) { if (DigitalIn(HP_RST).read() == 0) { if (hp == NULL) { - printf("setup HP communication handler\n"); + printf("setup HP communication handler\r\n"); hp = new HPSerial(HP_TX, HP_RX); } - - printf("!! RST !! (gstate=%d, state=%d)\n", + + printf("!! RST !! (gstate=%d, state=%d)\r\n", hp->gstate(), hp->state()); //printf("Value is ... %X\n", hp->search()); hp->startup(); @@ -499,7 +499,7 @@ char *oldv; char *txt; - + txt = (char *)malloc(strlen(intxt)+1); strcpy(txt, intxt); pulse(1, true); @@ -688,73 +688,72 @@ for (uint8_t i=0; i<8; i++) err[i] = 0; int p, pp; - p=0; - pp=0; + p = 0; + pp = 0; while(1) { if (knob != 0) - { - if (hp != NULL) { - printf("Sending keycode %X\n", knob); - hp->sendkey(knob); - printf(" DONE\n"); + { + if (hp != NULL) + { + printf("Sending keycode %X\r\n", knob); + hp->sendkey(knob); + printf(" DONE\r\n"); + } + knob = 0; } - knob = 0; - } if (cur_keycode.keyevent != KEY_NONE) - { - printf("Keycode %dx%d: %s\n", - cur_keycode.row, cur_keycode.col, - cur_keycode.keyevent==KEY_PRESSED?"pressed":"released"); - cur_keycode.keyevent = KEY_NONE; - } + { + printf("Keycode %dx%d: %s\r\n", + cur_keycode.row, cur_keycode.col, + cur_keycode.keyevent==KEY_PRESSED?"pressed":"released"); + cur_keycode.keyevent = KEY_NONE; + } p = qenc.getPulses(); - if (p != pp) { - printf("Pulses = %d\n", p); + if (p != pp) + { + printf("Pulses = %d\r\n", p); pp = p; } + if ((hp != NULL) && (hp->cmd_available())) { - led = 1; - HPSerial::CMD cmd; - if (hp->pop(cmd)) - { - for (uint8_t i=0; i<7; i++) - if (hp->nerrors(i) > err[i]) { - printf("ERR: %d/%d/%d/%d/%d/%d/%d\n", - hp->nerrors(0), - hp->nerrors(1), - hp->nerrors(2), - hp->nerrors(3), - hp->nerrors(4), - hp->nerrors(5), - hp->nerrors(6) - ); - break; - } - for (uint8_t i=0; i<7; i++) - err[i] = hp->nerrors(i); - printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd); + HPSerial::CMD cmd; + if (hp->pop(cmd)) + { + led = 1; + for (uint8_t i=0; i<7; i++) + if (hp->nerrors(i) > err[i]) { + printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n", + hp->nerrors(0), + hp->nerrors(1), + hp->nerrors(2), + hp->nerrors(3), + hp->nerrors(4), + hp->nerrors(5), + hp->nerrors(6) + ); + break; + } + for (uint8_t i=0; i<7; i++) + err[i] = hp->nerrors(i); - if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) - printf(": '%s'\n", cmd.value); - else { - printf(":"); - for (uint8_t i=0; i