Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bq40z80 core1 #7

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Bq40z80 core1 #7

wants to merge 23 commits into from

Conversation

tys76
Copy link
Contributor

@tys76 tys76 commented Mar 24, 2024

Verify bq40z80 in core 1 and display code

Base automatically changed from dev to master March 29, 2024 20:08
Copy link
Contributor

@rjp5th rjp5th left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments from things I saw- we can chat more tomorrow about this.


uint8_t sbh_mcu_serial_num = *(uint8_t *) (0x101FF000);
core1_init(sbh_mcu_serial_num);

async_i2c_init(PERIPH_SDA_PIN, PERIPH_SCL_PIN, -1, -1, 400000, 20);
display_init();
sht41_init(&sht41_sensor_error_cb, PERIPH_I2C);

sleep_ms(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this here?

panic("BQ40Z80 Init failed!");
uint8_t retry = 0;
while (!core1_get_pack_mfg_info(&bq_mfg_info)) {
if (++retry > 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this technically won't do anything since this doesn't block, so if we get to this point, it'll quickly fail 5 times rather than retrying 5 times (since it's up to core 1 for when it wants to retry).

I'd recommend some sort of logic to handle the battery being offline and recovering from that, but if that isn't possible, some sort of rate limit during initialization (but making sure we don't time out during safety ticking)

@@ -46,16 +93,104 @@ void display_show_stats(unsigned int serial, unsigned int soc, float voltage) {

ssd1306_FillRectangle(0, 11, 79, 32, White);
ssd1306_SetCursor(2, 13);
snprintf(buf, sizeof(buf), "SOC %d%%", soc);
if (op_hl == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for readability, this can be an enum rather than a raw int (or a define statement just to make the code easier to read)


char buf[16];
ssd1306_SetDisplayOn(1);
ssd1306_Fill(Black);

ssd1306_SetCursor(0, 0);
snprintf(buf, sizeof(buf), "ID: 2023-%d", serial); // TODO: Replace with real number
snprintf(buf, sizeof(buf), "ID: 2023-%d", serial);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never actually fixed the todo lol (this should be in MFG info though)

ssd1306_UpdateScreen();
}

void display_show_stats(unsigned int serial, unsigned int soc, float voltage) {
static void display_show_option(unsigned int serial, uint8_t op_hl, bool dsg_mode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason serial needs to be passed as a parameter rather than just pulling from core1 directly like you do for all these other values?

ssd1306_WriteString(buf, Font_11x18, Black);

ssd1306_SetCursor(86, 22);
snprintf(buf, sizeof(buf), "%.2fV", voltage);
if (dsg_mode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment, but do you think we could show something more useful here rather than charge or discharge mode, since we should know what we're doing to the battery, and I feel like if we have something else that we could show here, that would be better.


static void core1_bq40z80_error_cb(const bq_error type, const int error_code) {
if (type == BQ_ERROR_SAFETY_STATUS) {
safety_raise_fault_with_arg(FAULT_BQ40_SAFETY_STATUS, error_code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever show the safety status on the screen?

struct __packed {
enum __packed cmd_type {
BQ_POWER_CYCLE,
BQ_CYCLE_COUNT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some of these other commands, but I don't see them implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants