Skip to content

Commit

Permalink
Rename FAN_{GET,SET} to FAN_{GET,SET}_PWM
Browse files Browse the repository at this point in the history
Make the command and function names explicit that they are for
controlling fan PWM duty.

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Dec 31, 2024
1 parent 7ef6442 commit 88173de
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/board/system76/common/smfi.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static enum Result cmd_print(void) {
return RES_OK;
}

static enum Result cmd_fan_get(void) {
static enum Result cmd_fan_get_pwm(void) {
switch (smfi_cmd[SMFI_CMD_DATA]) {
case 1:
smfi_cmd[SMFI_CMD_DATA + 1] = fan1_pwm_actual;
Expand All @@ -139,7 +139,7 @@ static enum Result cmd_fan_get(void) {
return RES_ERR;
}

static enum Result cmd_fan_set(void) {
static enum Result cmd_fan_set_pwm(void) {
switch (smfi_cmd[SMFI_CMD_DATA]) {
case 1:
// Set duty cycle of FAN1
Expand Down Expand Up @@ -384,11 +384,11 @@ void smfi_event(void) {
case CMD_PRINT:
smfi_cmd[SMFI_CMD_RES] = cmd_print();
break;
case CMD_FAN_GET:
smfi_cmd[SMFI_CMD_RES] = cmd_fan_get();
case CMD_FAN_GET_PWM:
smfi_cmd[SMFI_CMD_RES] = cmd_fan_get_pwm();
break;
case CMD_FAN_SET:
smfi_cmd[SMFI_CMD_RES] = cmd_fan_set();
case CMD_FAN_SET_PWM:
smfi_cmd[SMFI_CMD_RES] = cmd_fan_set_pwm();
break;
case CMD_KEYMAP_GET:
smfi_cmd[SMFI_CMD_RES] = cmd_keymap_get();
Expand Down
8 changes: 4 additions & 4 deletions src/common/include/common/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ enum Command {
CMD_SPI = 5,
// Reset EC
CMD_RESET = 6,
// Get fan speeds
CMD_FAN_GET = 7,
// Set fan speeds
CMD_FAN_SET = 8,
// Get fan PWM duty
CMD_FAN_GET_PWM = 7,
// Set fan PWM duty
CMD_FAN_SET_PWM = 8,
// Get keyboard map index
CMD_KEYMAP_GET = 9,
// Set keyboard map index
Expand Down
12 changes: 6 additions & 6 deletions tool/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ enum Cmd {
Print = 4,
Spi = 5,
Reset = 6,
FanGet = 7,
FanSet = 8,
FanGetPwm = 7,
FanSetPwm = 8,
KeymapGet = 9,
KeymapSet = 10,
LedGetValue = 11,
Expand Down Expand Up @@ -187,22 +187,22 @@ impl<A: Access> Ec<A> {
}

/// Read fan duty cycle by fan index
pub unsafe fn fan_get(&mut self, index: u8) -> Result<u8, Error> {
pub unsafe fn fan_get_pwm(&mut self, index: u8) -> Result<u8, Error> {
let mut data = [
index,
0
];
self.command(Cmd::FanGet, &mut data)?;
self.command(Cmd::FanGetPwm, &mut data)?;
Ok(data[1])
}

/// Set fan duty cycle by fan index
pub unsafe fn fan_set(&mut self, index: u8, duty: u8) -> Result<(), Error> {
pub unsafe fn fan_set_pwm(&mut self, index: u8, duty: u8) -> Result<(), Error> {
let mut data = [
index,
duty
];
self.command(Cmd::FanSet, &mut data)
self.command(Cmd::FanSetPwm, &mut data)
}

/// Read keymap data by layout, output pin, and input pin
Expand Down
16 changes: 8 additions & 8 deletions tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ unsafe fn print(ec: &mut Ec<Box<dyn Access>>, message: &[u8]) -> Result<(), Erro
Ok(())
}

unsafe fn fan_get(ec: &mut Ec<Box<dyn Access>>, index: u8) -> Result<(), Error> {
let duty = ec.fan_get(index)?;
unsafe fn fan_get_pwm(ec: &mut Ec<Box<dyn Access>>, index: u8) -> Result<(), Error> {
let duty = ec.fan_get_pwm(index)?;
println!("{}", duty);

Ok(())
}

unsafe fn fan_set(ec: &mut Ec<Box<dyn Access>>, index: u8, duty: u8) -> Result<(), Error> {
ec.fan_set(index, duty)
unsafe fn fan_set_pwm(ec: &mut Ec<Box<dyn Access>>, index: u8, duty: u8) -> Result<(), Error> {
ec.fan_set_pwm(index, duty)
}

unsafe fn keymap_get(ec: &mut Ec<Box<dyn Access>>, layer: u8, output: u8, input: u8) -> Result<(), Error> {
Expand Down Expand Up @@ -316,7 +316,7 @@ fn parse_color(s: &str) -> Result<(u8, u8, u8), String> {
#[clap(rename_all = "snake_case")]
enum SubCommand {
Console,
Fan {
FanPwm {
index: u8,
duty: Option<u8>,
},
Expand Down Expand Up @@ -438,16 +438,16 @@ fn main() {
process::exit(1);
},
},
SubCommand::Fan { index, duty } => {
SubCommand::FanPwm { index, duty } => {
match duty {
Some(duty) => match unsafe { fan_set(&mut ec, index, duty) } {
Some(duty) => match unsafe { fan_set_pwm(&mut ec, index, duty) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to set fan {} to {}: {:X?}", index, duty, err);
process::exit(1);
},
},
None => match unsafe { fan_get(&mut ec, index) } {
None => match unsafe { fan_get_pwm(&mut ec, index) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to get fan {}: {:X?}", index, err);
Expand Down

0 comments on commit 88173de

Please sign in to comment.