Skip to content

Commit

Permalink
GM: abstract PCM-related hw check (#1090)
Browse files Browse the repository at this point in the history
abstract hw check to if pcm_cruise or not
  • Loading branch information
sshane authored Oct 9, 2022
1 parent 1303af2 commit ca11326
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum {
};

enum {GM_ASCM, GM_CAM} gm_hw = GM_ASCM;
bool gm_pcm_cruise = false;

static int gm_rx_hook(CANPacket_t *to_push) {

Expand All @@ -73,7 +74,7 @@ static int gm_rx_hook(CANPacket_t *to_push) {
}

// ACC steering wheel buttons (GM_CAM is tied to the PCM)
if ((addr == 481) && (gm_hw == GM_ASCM)) {
if ((addr == 481) && !gm_pcm_cruise) {
int button = (GET_BYTE(to_push, 5) & 0x70U) >> 4;

// exit controls on cancel press
Expand Down Expand Up @@ -101,7 +102,7 @@ static int gm_rx_hook(CANPacket_t *to_push) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;

// enter controls on rising edge of ACC, exit controls when ACC off
if (gm_hw == GM_CAM) {
if (gm_pcm_cruise) {
bool cruise_engaged = (GET_BYTE(to_push, 1) >> 5) != 0U;
pcm_cruise_check(cruise_engaged);
}
Expand Down Expand Up @@ -234,7 +235,7 @@ static int gm_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
}

// BUTTONS: used for resume spamming and cruise cancellation with stock longitudinal
if ((addr == 481) && (gm_hw == GM_CAM)) {
if ((addr == 481) && gm_pcm_cruise) {
int button = (GET_BYTE(to_send, 5) >> 4) & 0x7U;

bool allowed_cancel = (button == 6) && cruise_engaged_prev;
Expand Down Expand Up @@ -271,6 +272,7 @@ static int gm_fwd_hook(int bus_num, CANPacket_t *to_fwd) {

static const addr_checks* gm_init(uint16_t param) {
gm_hw = GET_FLAG(param, GM_PARAM_HW_CAM) ? GM_CAM : GM_ASCM;
gm_pcm_cruise = gm_hw == GM_CAM;
return &gm_rx_checks;
}

Expand Down

0 comments on commit ca11326

Please sign in to comment.