Skip to content

Commit

Permalink
Keep GPIOs as outputs until all segments updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpalladino committed Oct 5, 2024
1 parent 6d93ad9 commit 036e908
Showing 1 changed file with 23 additions and 60 deletions.
83 changes: 23 additions & 60 deletions tcg_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
};

Expand Down

0 comments on commit 036e908

Please sign in to comment.