Skip to content

Commit

Permalink
Hopefully fix I2C bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dewar committed Mar 26, 2024
1 parent 60fa582 commit 76231fd
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
Binary file modified microfw/CW310/src/CW310.bin
Binary file not shown.
Binary file modified microfw/CW310/src/CW340.bin
Binary file not shown.
7 changes: 2 additions & 5 deletions microfw/CW310/src/main_cw310.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void fpga_pins(bool enabled)
gpio_configure_pin(PIN_EBI_ADDR_BUS_A17, PIN_EBI_DATA_BUS_FLAG1);
gpio_configure_pin(PIN_EBI_ADDR_BUS_A18, PIN_EBI_DATA_BUS_FLAG1);
gpio_configure_pin(PIN_EBI_ADDR_BUS_A19, PIN_EBI_DATA_BUS_FLAG1);
gpio_configure_pin(FPGA_ALE_GPIO, FPGA_ALE_FLAGS);
// gpio_configure_pin(FPGA_ALE_GPIO, FPGA_ALE_FLAGS);
//gpio_configure_pin(PIN_EBI_ADDR_BUS_A20, PIN_EBI_DATA_BUS_FLAG1); /* TODO: Add ADDR20 back */


Expand Down Expand Up @@ -174,7 +174,7 @@ void fpga_pins(bool enabled)
//gpio_configure_group(FPGA_ADDR_PORT, FPGA_ADDR_PINS, PIO_INPUT);

//ALE pin under SW control
gpio_configure_pin(FPGA_ALE_GPIO, PIO_INPUT);
// gpio_configure_pin(FPGA_ALE_GPIO, PIO_INPUT);

//Force FPGA trigger
gpio_configure_pin(FPGA_TRIGGER_GPIO, PIO_INPUT);
Expand Down Expand Up @@ -305,9 +305,6 @@ int main(void)
reset_reason = reset_reason; //Still a thing in 2021??
WDT->WDT_MR = (1 << 25); //disable watchdog

// unlock I2C
I2C_LOCK = 0;

//Convert serial number to ASCII for USB Serial number
uint32_t serial_number[4];
flash_read_unique_id(serial_number, sizeof(serial_number));
Expand Down
2 changes: 1 addition & 1 deletion microfw/CW310/src/naeusb
Submodule naeusb updated 3 files
+42 −2 i2c_util.c
+6 −2 i2c_util.h
+1 −1 sam3u_hal/inc/twi.h
20 changes: 7 additions & 13 deletions microfw/CW310/src/naeusb_bergen.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "naeusb.h"
#include "naeusb_bergen.h"
#include "naeusb_default.h"
#include "i2c_util.h"

int max1617_register_read(uint8_t reg_addr, int8_t *result);

Expand Down Expand Up @@ -42,16 +43,14 @@ void ctrl_i2c_send(void)
if (udd_g_ctrlreq.req.wLength > udd_g_ctrlreq.payload_size)
return;

if (I2C_LOCK) {
if (i2c_is_locked()) {
I2C_STATUS = 1;
return;
}

USER_TWI_PACKET.buffer = udd_g_ctrlreq.payload;
USER_TWI_PACKET.length = udd_g_ctrlreq.req.wLength;
I2C_LOCK = 1;
I2C_STATUS = twi_master_write(TWI0, &USER_TWI_PACKET);
I2C_LOCK = 0;
raw_i2c_send(&USER_TWI_PACKET);
}

void ctrl_i2c_setup(void)
Expand All @@ -73,13 +72,11 @@ void ctrl_i2c_setup(void)

void ctrl_fpga_temp_cb(void)
{
if (I2C_LOCK) {
if (i2c_is_locked()) {
I2C_STATUS = 1;
return;
}
I2C_LOCK = 1;
max1617_register_write(udd_g_ctrlreq.req.wValue & 0xFF, udd_g_ctrlreq.payload[0]);
I2C_LOCK = 0;
I2C_STATUS = 0;
}

Expand Down Expand Up @@ -115,7 +112,7 @@ bool bergen_setup_in_received(void)
switch (udd_g_ctrlreq.req.bRequest & 0xFF) {
case REQ_FPGA_TEMP:
addr = udd_g_ctrlreq.req.wValue & 0xFF;
if (I2C_LOCK) {
if (i2c_is_locked()) {
respbuf[0] = 1;
udd_g_ctrlreq.payload = respbuf;
udd_g_ctrlreq.payload_size = 1;
Expand All @@ -142,18 +139,15 @@ bool bergen_setup_in_received(void)
case REQ_I2C_DATA:
USER_TWI_PACKET.length = udd_g_ctrlreq.req.wLength;
USER_TWI_PACKET.buffer = respbuf + 1;
if (I2C_LOCK) {
if (i2c_is_locked()) {
respbuf[0] = 1;
I2C_STATUS = 1;
udd_g_ctrlreq.payload = respbuf;
udd_g_ctrlreq.payload_size = USER_TWI_PACKET.length + 1;
return true;
}

I2C_LOCK = 1;
twi_master_read(TWI0, &USER_TWI_PACKET);
raw_i2c_read(&USER_TWI_PACKET);
respbuf[0] = 0;
I2C_LOCK = 0;
udd_g_ctrlreq.payload = respbuf;
udd_g_ctrlreq.payload_size = USER_TWI_PACKET.length + 1;
return true;
Expand Down
2 changes: 0 additions & 2 deletions microfw/CW310/src/naeusb_board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#ifdef __PLAT_CW340__

extern volatile uint8_t I2C_LOCK;
extern uint8_t FPGA_PINS_ON;


Expand Down Expand Up @@ -256,7 +255,6 @@ void kill_fpga_power(void);
* Author: adewa
*/

extern volatile uint8_t I2C_LOCK;
extern uint8_t FPGA_PINS_ON;


Expand Down
4 changes: 2 additions & 2 deletions microfw/CW310/src/usbc_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Must be done after setting new power settings
*/
int usb_pd_soft_reset(void)
{
if (I2C_LOCK)
if (i2c_is_locked())
return -1;
I2C_LOCK = 1;

uint8_t cmd = 0x0D;
int rtn;

Expand Down

0 comments on commit 76231fd

Please sign in to comment.