0hmX/pcbgolf-routing-checkpoint-20261012
A PCBGolf assembly combining a modeled PCB with copper/component bodies and seven native connector housings.
- Version
- 0.0.3
- License
- unset
- Stars
- 0
firmware-support/pcbgolf_board.h
#pragma once
#include <stdbool.h>
#include <stdint.h>
#define PCBGOLF_PORTS 4U
#define PCBGOLF_HSE_HZ 25000000U
#define PCBGOLF_ADC_SAMPLE_CYCLES 810U
#define PCBGOLF_IMON_OHMS 4700U
#define PCBGOLF_IMON_V_PER_A 0.24581f
#define PCBGOLF_IMON_ZERO_V 0.00376f
typedef struct { char bank; uint8_t pin; } pcbgolf_pin_t;
typedef struct { pcbgolf_pin_t pin; uint8_t adc, channel, bits; } pcbgolf_adc_t;
typedef struct { float zero_v, volts_per_a; } pcbgolf_imon_cal_t;
extern const pcbgolf_adc_t pcbgolf_imon[4];
extern const pcbgolf_adc_t pcbgolf_sbu[4][2];
/* Call after clock startup. Drivers must separately initialize ADC/CAN/USB/SD/I2C. */
void pcbgolf_gpio_init(void);
bool pcbgolf_set_vdda_health(uint16_t measured_mv);
bool pcbgolf_set_port_power(uint8_t one_based_port, bool enabled);
bool pcbgolf_set_can_enabled(uint8_t transceiver_zero_based, bool enabled);
bool pcbgolf_select_fdcan2(bool alternate_can3);
bool pcbgolf_set_sbu(uint8_t one_based_port, uint8_t sbu_zero_based, bool relay, bool enabled);
bool pcbgolf_button_pressed(void);
/* Calibration must be stored independently for each of the four ports. */
bool pcbgolf_fit_imon(float zero_v, float known_v, float known_a, pcbgolf_imon_cal_t *cal);
bool pcbgolf_imon_current(uint32_t raw, uint8_t bits, float measured_vref_v,
const pcbgolf_imon_cal_t *cal, float *current_a);