void SetDigitalOutLevel(int pin, int value) { log_printf("SetDigitalOutLevel(%d, %d)", pin, value); SAVE_PIN_FOR_LOG(pin); BYTE prev = SyncInterruptLevel(4); PinSetLat(pin, value); SyncInterruptLevel(prev); }
void SetPinUart(int pin, int uart_num, int dir, int enable) { log_printf("SetPinUart(%d, %d, %d, %d)", pin, uart_num, dir, enable); SAVE_PIN_FOR_LOG(pin); SAVE_UART_FOR_LOG(uart_num); if (dir) { // TX const BYTE rp[] = { 3, 5, 28, 30 }; PinSetRpor(pin, enable ? rp[uart_num] : 0); } else { // RX int rpin = enable ? PinToRpin(pin) : 0x3F; switch (uart_num) { case 0: _U1RXR = rpin; break; case 1: _U2RXR = rpin; break; case 2: _U3RXR = rpin; break; case 3: _U4RXR = rpin; break; } } }
void SetDigitalOutLevel(int pin, int value) { heartbeat(); //ANDROID THERMOSTAT MOD log_printf("SetDigitalOutLevel(%d, %d)", pin, value); SAVE_PIN_FOR_LOG(pin); BYTE prev = SyncInterruptLevel(4); PinSetLat(pin, value); SyncInterruptLevel(prev); }
static void SendDigitalInStatusMessage(int pin, int value) { log_printf("SendDigitalInStatusMessage(%d, %d)", pin, value); SAVE_PIN_FOR_LOG(pin); OUTGOING_MESSAGE msg; msg.type = REPORT_DIGITAL_IN_STATUS; msg.args.report_digital_in_status.pin = pin; msg.args.report_digital_in_status.level = value; AppProtocolSendMessage(&msg); }
void SetPinAnalogIn(int pin) { log_printf("SetPinAnalogIn(%d)", pin); SAVE_PIN_FOR_LOG(pin); PinSetRpor(pin, 0); PinSetCnen(pin, 0); PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); PinSetAnsel(pin, 1); PinSetTris(pin, 1); }
void SetPinAnalogIn(int pin) { log_printf("SetPinAnalogIn(%d)", pin); SAVE_PIN_FOR_LOG(pin); PinSetRpor(pin, 0); PinSetCnen(pin, 0); PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); PinSetAnsel(pin, 1); PinSetTris(pin, 1); ADCSetScan(pin, 0); //ANDROID THERMOSTAT MOD }
void SetChangeNotify(int pin, int changeNotify) { int cnie_backup = _CNIE; log_printf("SetChangeNotify(%d, %d)", pin, changeNotify); SAVE_PIN_FOR_LOG(pin); _CNIE = 0; PinSetCnen(pin, changeNotify); if (changeNotify) { PinSetCnforce(pin); _CNIF = 1; // force a status message on the new pin } _CNIE = cnie_backup; }
void SetPinDigitalOut(int pin, int value, int open_drain) { log_printf("SetPinDigitalOut(%d, %d, %d)", pin, value, open_drain); SAVE_PIN_FOR_LOG(pin); ADCSetScan(pin, 0); PinSetAnsel(pin, 0); PinSetRpor(pin, 0); PinSetCnen(pin, 0); PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); PinSetLat(pin, value); PinSetOdc(pin, open_drain); PinSetTris(pin, 0); }
void SetPinCapSense(int pin) { log_printf("SetPinCapSense(%d)", pin); SAVE_PIN_FOR_LOG(pin); // In cap-sense mode, the pin is configured for analog input, but initially // pulling low in order to discharge, the circuit. PinSetRpor(pin, 0); PinSetCnen(pin, 0); PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); PinSetAnsel(pin, 1); PinSetLat(pin, 0); PinSetTris(pin, 1); }
void SetPinDigitalOut(int pin, int value, int open_drain) { log_printf("SetPinDigitalOut(%d, %d, %d)", pin, value, open_drain); SAVE_PIN_FOR_LOG(pin); // Protect from the user trying to use push-pull, later pulling low using the // bootloader pin. if (pin == 0) open_drain = 1; PinSetAnsel(pin, 0); PinSetRpor(pin, 0); PinSetCnen(pin, 0); PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); PinSetLat(pin, value); PinSetOdc(pin, open_drain); PinSetTris(pin, 0); }
void SetPinSpi(int pin, int spi_num, int mode, int enable) { log_printf("SetPinSpi(%d, %d, %d, %d)", pin, spi_num, mode, enable); SAVE_PIN_FOR_LOG(pin); switch (mode) { case 0: // data out { const BYTE rp[] = { 7, 10, 32 }; PinSetRpor(pin, enable ? rp[spi_num] : 0); } break; case 1: // data in { int rpin = enable ? PinToRpin(pin) : 0x3F; switch (spi_num) { case 0: _SDI1R = rpin; break; case 1: _SDI2R = rpin; break; case 2: _SDI3R = rpin; break; } } break; case 2: // clk out { const BYTE rp[] = { 8, 11, 33 }; PinSetRpor(pin, enable ? rp[spi_num] : 0); } break; } }
void SetPinDigitalIn(int pin, int pull) { log_printf("SetPinDigitalIn(%d, %d)", pin, pull); SAVE_PIN_FOR_LOG(pin); PinSetAnsel(pin, 0); PinSetRpor(pin, 0); PinSetCnen(pin, 0); switch (pull) { case 1: PinSetCnpd(pin, 0); PinSetCnpu(pin, 1); break; case 2: PinSetCnpu(pin, 0); PinSetCnpd(pin, 1); break; default: PinSetCnpu(pin, 0); PinSetCnpd(pin, 0); } PinSetTris(pin, 1); }
void SetPinPwm(int pin, int pwm_num, int enable) { log_printf("SetPinPwm(%d, %d)", pin, pwm_num); SAVE_PIN_FOR_LOG(pin); PinSetRpor(pin, enable ? (pwm_num == 8 ? 35 : 18 + pwm_num) : 0); }