From 036e9084cb822394e2a36f7c7ebb65ba7add750f Mon Sep 17 00:00:00 2001 From: Nick <53413353+nickpalladino@users.noreply.github.com> Date: Sat, 5 Oct 2024 14:52:29 -0400 Subject: [PATCH] Keep GPIOs as outputs until all segments updated --- tcg_counter.c | 83 ++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 60 deletions(-) diff --git a/tcg_counter.c b/tcg_counter.c index b39dbbf..cb08d4a 100644 --- a/tcg_counter.c +++ b/tcg_counter.c @@ -87,90 +87,53 @@ uint16_t __attribute__ ((noinline)) cmd_a3(){ return 0; } -uint16_t __attribute__ ((noinline)) cmd_segment_on(){ - uint8_t segment; - // CRC_LENGTH + 1 byte expected - if( RF13MFIFOFL_L == 2 + 1) { - - // pull one byte from the recieve FIFO - segment=RF13MRXF_L; - - uint8_t bits = segment_to_bits(segment); - - // disable internal resistors - P1REN &= 0x00; - // set output direction - P1DIR |= bits | BIT0; - // set specified segment 1.5V, set segment z common electrode = 0V - P1OUT = (P1OUT & ~BIT0) | bits; - - //Zero byte for success. - RF13MTXF_L = 0; - - } else { - // Error - RF13MRXF=1; - } +uint16_t __attribute__ ((noinline)) cmd_set_port1_output(){ + + // set all GPIOs to output direction + P1DIR |= 0xFF; + + //Zero byte for success. + RF13MTXF_L = 0; return 0; } -uint16_t __attribute__ ((noinline)) cmd_segment_off(){ - uint8_t segment; +uint16_t __attribute__ ((noinline)) cmd_set_port1_high_z(){ + + // disable internal resistors + P1REN &= 0x00; - // CRC_LENGTH + 1 byte expected - if( RF13MFIFOFL_L == 2 + 1) { - - // pull one byte from the recieve FIFO - segment=RF13MRXF_L; + // put in input mode for high z state + P1DIR &= 0x00; - uint8_t bits = segment_to_bits(segment); - - // disable internal resistors - P1REN &= 0x00; - // set output direction - P1DIR |= bits | BIT0; - // set specified segment 0V, set segment z common electrode = 1.5V - P1OUT = (P1OUT & ~bits) | BIT0; - - //Zero byte for success. - RF13MTXF_L = 0; - - } else { - // Error - RF13MRXF=1; - } + //Zero byte for success. + RF13MTXF_L = 0; return 0; } -uint16_t __attribute__ ((noinline)) cmd_segment_high_z(){ - uint8_t segment; +uint16_t __attribute__ ((noinline)) cmd_set_port1_bits(){ + uint8_t port1_bits; // CRC_LENGTH + 1 byte expected if( RF13MFIFOFL_L == 2 + 1) { // pull one byte from the recieve FIFO - segment=RF13MRXF_L; + port1_bits=RF13MRXF_L; - uint8_t bits = segment_to_bits(segment); - - // disable internal resistors - P1REN &= 0x00; - // put in input mode for high z state - P1DIR &= ~bits; + P1OUT = port1_bits; //Zero byte for success. RF13MTXF_L = 0; } else { - // Error RF13MRXF=1; } return 0; } + // expects segments 1-7 uint8_t segment_to_bits(uint8_t segment) { return 1 << segment; @@ -196,9 +159,9 @@ const uint16_t patchtable[0x12] = 0xCECE, 0xCECE, 0xCECE, 0xCECE, 0xCECE, 0xCECE, - (uint16_t) cmd_segment_high_z, 0x00A3, //Handler address and command number. - (uint16_t) cmd_segment_on, 0x00A0, //Handler address and command number. - (uint16_t) cmd_segment_off, 0x00A1, //Handler address and command number. + (uint16_t) cmd_set_port1_bits, 0x00A3, //Handler address and command number. + (uint16_t) cmd_set_port1_high_z, 0x00A0, //Handler address and command number. + (uint16_t) cmd_set_port1_output, 0x00A1, //Handler address and command number. 0xCECE, //This ABSOLUTELY MUST be at 0xFFCE or your patch won't load. };