void adjust_fan(uint32_t pwm) { static uint32_t value = 0x3ff; if (value == pwm) return; value = pwm; if (value < 0) value = 0; if (value > 0x3ff) value = 0x3ff; write_pwm(value); }
void write_motor(uint8_t motor, int16_t val) { uint8_t pin0 = (motor < 4)? (motor * 2) : ((motor-4)*2); //For PORTA vs PORTC //volatile uint8_t* hport = (motor < 4)? &PORTA : &PORTC; //*hport |= (1 << (val > 0)? pin0 : (pin0+1)); //*hport &= ~(1 << (val < 0)? pin0 : (pin0+1)); write_pwm(motor, (val > 0)? val : ((signed)-val)); //write positive value to pwm EN pin if (motor == 5 || motor == 3) { val = -val; }//reverse these chanles if (motor < 4){ PORTA |= (1 << ((val >= 0)? pin0 : (pin0+1))); PORTA &= ~(1 << ((val >= 0)? (pin0+1) : pin0)); } else { PORTC |= (1 << ((val >= 0)? pin0 : (pin0+1))); PORTC &= ~(1 << ((val >= 0)? (pin0+1) : pin0)); } }