diff --git a/8seg_digit_circuit.svg b/8seg_digit_circuit.svg
new file mode 100644
index 0000000..f67610d
--- /dev/null
+++ b/8seg_digit_circuit.svg
@@ -0,0 +1,1065 @@
+
+
+
+
diff --git a/8seg_strand_power_distribution.svg b/8seg_strand_power_distribution.svg
new file mode 100644
index 0000000..abbbb7e
--- /dev/null
+++ b/8seg_strand_power_distribution.svg
@@ -0,0 +1,500 @@
+
+
+
+
diff --git a/center_fw/.gdbinit b/center_fw/.gdbinit
index 766b39d..0a93b51 100644
--- a/center_fw/.gdbinit
+++ b/center_fw/.gdbinit
@@ -1,5 +1,5 @@
-target extended-remote 192.168.1.97:2022
+target extended-remote 192.168.27.119:2022
set print pretty on
set print elements 512
@@ -29,7 +29,3 @@ define jdump
end
end
-define reconnect
- disconnect
- target extended-remote 192.168.1.97:2022
-end
diff --git a/center_fw/src/main.c b/center_fw/src/main.c
index c066297..8c91607 100644
--- a/center_fw/src/main.c
+++ b/center_fw/src/main.c
@@ -209,7 +209,7 @@ void ADC1_IRQHandler(void) {
/* Read sample and apply threshold */
int sample = ADC1->DR; /* resets the EOC interrupt flag */
- int bit = sample > THRESHOLD_ADC_COUNTS;
+ int bit = sample < THRESHOLD_ADC_COUNTS;
int bit_margin = ((int)sample) - THRESHOLD_ADC_COUNTS;
if (bit_margin < 0) {
bit_margin = -bit_margin;
diff --git a/driver/driver.kicad_pro b/driver/driver.kicad_pro
index f58a869..4c2a585 100644
--- a/driver/driver.kicad_pro
+++ b/driver/driver.kicad_pro
@@ -273,6 +273,13 @@
],
"zones_allow_external_fillets": false
},
+ "ipc2581": {
+ "dist": "",
+ "distpn": "",
+ "internal_id": "",
+ "mfg": "",
+ "mpn": ""
+ },
"layer_presets": [],
"viewports": []
},
diff --git a/driver_fw/.gdbinit b/driver_fw/.gdbinit
index a8b0d69..0e81bd4 100644
--- a/driver_fw/.gdbinit
+++ b/driver_fw/.gdbinit
@@ -1,5 +1,16 @@
-target extended-remote 192.168.1.95:2022
+# blackmagic-1
+# target extended-remote 192.168.27.252:2022
+
+# blackmagic-2
+# target extended-remote 193.168.27.114:2022
+
+# blackmagic-3
+target extended-remote 192.168.27.207:2022
+
+# blackmagic-4
+# target extended-remote 192.168.27.153:2022
+
set print pretty on
set print elements 512
@@ -18,8 +29,3 @@ end
source ~/ref/PyCortexMDebug/cmdebug/svd_gdb.py
svd_load ~/ref/stm32square/svd/STM32G070.svd
-define reconnect
- disconnect
- target extended-remote 192.168.1.95:2022
-end
-
diff --git a/driver_fw/Makefile b/driver_fw/Makefile
index fb4be18..9afcbb5 100644
--- a/driver_fw/Makefile
+++ b/driver_fw/Makefile
@@ -9,7 +9,7 @@ MUSL_DIR ?= upstream/musl
# Algorithm parameters
########################################################################################################################
-# - none -
+DRIVER_ADDR ?= 0
########################################################################################################################
# High-level build parameters
@@ -91,7 +91,7 @@ CFLAGS += -fno-common -ffunction-sections -fdata-sections
COMMON_CFLAGS += -O$(OPT) -std=gnu2x -g
COMMON_CFLAGS += $(DEVICE_DEFINES)
-COMMON_CFLAGS += -DDEBUG=$(DEBUG)
+COMMON_CFLAGS += -DDEBUG=$(DEBUG) -DDRIVER_ADDR=$(DRIVER_ADDR)
GEN_HEADERS := $(BUILDDIR)/generated/waveform_tables.h
diff --git a/driver_fw/src/main.c b/driver_fw/src/main.c
index d5b0e83..db0f1b0 100644
--- a/driver_fw/src/main.c
+++ b/driver_fw/src/main.c
@@ -17,7 +17,6 @@ static void dma_tx_waveform(size_t table_size, const uint16_t *table);
#define SYNC_INTERVAL 13
-static size_t time_to_sync = 0;
static size_t tx_bitpos = 0;
static size_t tx_sympos = 0;
static int tx_last_bit = 0;
@@ -36,7 +35,37 @@ static union tx_buf_union *tx_buf_write = &tx_buf[2];
static bool idle_buf_ready = false;
void update_tx_buf(void);
+int hex_to_int(char *hex, size_t len);
+int hex_to_int(char *hex, size_t len) {
+ int rv = 0;
+ while (len--) {
+ rv = rv<<4;
+ char c = hex[len];
+ if ('0' <= c && c <= '9')
+ c = c - '0';
+ else if ('a' <= c && c <= 'f')
+ c = c - 'a' + 0xa;
+ else if ('A' <= c && c <= 'F')
+ c = c - 'A' + 0xa;
+ else
+ c = 0;
+ rv |= c;
+ }
+ return rv;
+}
+
+enum leds {
+ LED_ON = 1,
+ LED_PING = 2,
+ LED_OVERHEAT = 4,
+ LED_CONTROL_ERR = 8,
+ LED_INPUT_ERR = 16,
+ LED_OUTPUT_ERR = 32
+};
+
+char rxbuf[256];
+size_t rxp = 0;
int main(void) {
/* Configure clocks for 64 MHz system clock.
@@ -132,7 +161,9 @@ int main(void) {
GPIOB->OSPEEDR = (3<<0) | (3<<1) | (3<<3);
/* GPIOC:
- * C0-C3: (testpoint)
+ * C0, C3: (testpoint)
+ * C1: Fan 2 PWM
+ * C2: Fan 1 PWM
* C4: RJ45 LED 4
* C5: RJ45 LED 3
* C6: Fuse monitor 7
@@ -143,12 +174,14 @@ int main(void) {
* C11-C15: (testpoint)
*/
GPIOC->MODER =
- IN(0) | IN(1) | IN(2) | IN(3) | IN(9) | IN(11) | IN(12) | IN(13) | IN(14) | IN(15) |
+ IN(0) | OUT(1) | OUT(2) | IN(3) | IN(9) | IN(11) | IN(12) | IN(13) | IN(14) | IN(15) |
OUT(4) | OUT(5) |
IN(6) | IN(7) | IN(8) |
AF(10);
+ GPIOC->OTYPER = (1<<1) | (1<<2);
GPIOC->AFR[1] = AFRH(10, 2);
GPIOC->OSPEEDR = (3<<10);
+ GPIOC->BRR = (1<<1) | (1<<2); /* Turn down fans (most fans don't turn off at 0% PWM) */
/* GPIOD:
* D0-D6: (testpoint)
@@ -158,6 +191,22 @@ int main(void) {
GPIOD->MODER = IN(0) | IN(1) | IN(2) | IN(3) | IN(4) | IN(5) | IN(6) |
IN(8) | IN(9);
+ for (int i=0; i<10; i++) {
+ set_status_leds(LED_ON);
+ delay_us(250*1000);
+ set_status_leds(0);
+ delay_us(250*1000);
+ }
+
+ GPIOC->BSRR = (1<<1) | (1<<2); /* Enable fans */
+
+ for (int i=0; i<10; i++) {
+ set_status_leds(LED_ON);
+ delay_us(250*1000);
+ set_status_leds(0);
+ delay_us(250*1000);
+ }
+
TIM1->CCMR1 = (6<CCMR2 = (6<CCER = TIM_CCER_CC2E | TIM_CCER_CC2NE | TIM_CCER_CC2NP | TIM_CCER_CC3E | TIM_CCER_CC3NE | TIM_CCER_CC3P;
@@ -177,38 +226,79 @@ int main(void) {
dma_tx_constant(COUNT_OF(waveform_zero_one), 0x00);
xfr_8b10b_encode_reset(&encoder_state_8b10b);
- int i = 0;
- int j = 0;
- int k = 0;
- int n = 0;
+ USART1->CR1 = /* 8-bit -> M1, M0 clear */
+ /* OVER8 clear. Use default 16x oversampling */
+ /* CMIF clear */
+ /* MME clear */
+ /* WAKE clear */
+ /* PCE, PS clear */
+ /* RXNEIE, other interrupts clear */
+ USART_CR1_TE
+ | USART_CR1_RE;
+ USART1->CR3 |= USART_CR3_DEM; /* Output DE signal on RTS pin */
+ USART1->BRR = 6667; /* Set baudrate to 9600 Bd */
+ USART1->CR1 |= USART_CR1_UE; /* And... go! */
+
+ int rj45_rx_ctr = 0;
+ int ping_ctr = 0;
+ int control_err_ctr = 0;
while (23) {
- i++;
- j++;
- i %= 6;
- j %= 4;
- delay_us(30000);
- set_rj45_leds(1 << j);
- set_status_leds(1 << i);
- if (i == 0) {
- k++;
- if (k == 16) {
- k = 0;
- n++;
- if (n == 16) {
- n = 0;
+ if (rj45_rx_ctr) {
+ set_rj45_leds(0x5);
+ rj45_rx_ctr--;
+
+ } else {
+ set_rj45_leds(0x0);
+ }
+
+ int leds = LED_ON;
+ if (ping_ctr) {
+ leds |= LED_PING;
+ ping_ctr--;
+ }
+ if (control_err_ctr) {
+ leds |= LED_CONTROL_ERR;
+ control_err_ctr--;
+ }
+ set_status_leds(leds);
+
+ int isr = USART1->ISR;
+ if ((isr & USART_ISR_ORE) || (isr & USART_ISR_FE)) {
+ USART1->ICR = USART_ICR_ORECF | USART_ICR_FECF;
+ }
+
+ if (isr & USART_ISR_RXNE_RXFNE) {
+ rj45_rx_ctr = 20000;
+ char c = USART1->RDR;
+ if (c == '\n') {
+ if (rxp > 2 && rxp != 4*16*3) {
+ control_err_ctr = 1000000;
+ rxp = 0;
+ continue;
+ }
+
+ for (size_t i=0; i<16; i++) {
+ int brightness = hex_to_int(&rxbuf[DRIVER_ADDR*16*3 + i*3], 1);
+ int channels = hex_to_int(&rxbuf[DRIVER_ADDR*16*3 + i*3 + 1], 2);
+
+ tx_buf_write->packet.channels[i] = channels;
+
+ if ((i&1) == 0) {
+ tx_buf_write->packet.brightness[i>>1] = brightness;
+ } else {
+ tx_buf_write->packet.brightness[i>>1] |= brightness<<4;
+ }
+ }
+ rxp = 0;
+ ping_ctr = 500000;
+ update_tx_buf();
+
+ } else {
+ if (rxp <= sizeof(rxbuf)) {
+ rxbuf[rxp] = c;
+ rxp ++;
}
}
-
- uint8_t b = (k < 8) ? (1<packet.channels); i++) {
- tx_buf_write->packet.channels[i] = 0xff;
- }
- for (size_t i=0; ipacket.brightness); i++) {
- tx_buf_write->packet.brightness[i] = 0xff; //(n<<4) | n;
- }
- update_tx_buf();
}
}
}
@@ -243,7 +333,6 @@ size_t cnd_pos = 0;
void DMA1_Channel1_IRQHandler() {
static int transfer_errors = 0;
static int current_symbol = 0;
- static int idle_symbol = 0;
if (DMA1->ISR & DMA_ISR_TEIF1) {
transfer_errors ++;
@@ -272,32 +361,23 @@ void DMA1_Channel1_IRQHandler() {
sym_arr[sym_pos] = -255;
- idle_symbol++;
- if (idle_symbol == 3) {
- current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, -K23_7);
- idle_symbol = 0;
-
- } else if (tx_sympos == sizeof(struct data_packet)) {
- if (time_to_sync > 0) {
- current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, -K27_7);
- sym_arr[sym_pos] = current_symbol;
- time_to_sync--;
-
- } else {
- current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, -K28_1);
- sym_arr[sym_pos] = current_symbol;
- packet_rng_state = xorshift32(1);
- time_to_sync = SYNC_INTERVAL;
- }
-
+ if (tx_sympos == sizeof(struct data_packet)) {
if (idle_buf_ready) {
union tx_buf_union *tmp = tx_buf_idle;
tx_buf_idle = tx_buf_read;
tx_buf_read = tmp;
idle_buf_ready = false;
- }
- tx_sympos = 0;
+ current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, -K28_1);
+ sym_arr[sym_pos] = current_symbol;
+ packet_rng_state = xorshift32(1);
+
+ tx_sympos = 0;
+
+ } else {
+ current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, -K23_7);
+ sym_arr[sym_pos] = current_symbol;
+ }
} else {
uint8_t b = tx_buf_read->bytes[tx_sympos];
diff --git a/led_tape.svg b/led_tape.svg
index 6999959..3d7796f 100644
--- a/led_tape.svg
+++ b/led_tape.svg
@@ -2,21 +2,21 @@