示例#1
0
// assemble flags byte for DIO
//   bit0 of flags -- can input
//   bit1 of flags -- input is active low
//   bit2 of flags -- can output push-pull
//   bit3 of flags -- can output open-drain
//   bit4 of flags -- output is active low
uint8_t make_flags(uint8_t canIn, uint8_t pushPull, uint8_t openDr,
  uint8_t outAL) {
  uint8_t flagbyte = (uint8_t) (canIn & 1);
  flagbyte |= ((DIGITAL_READ(IN0)) << 1);
  flagbyte |= ((pushPull & 1) << 2);
  flagbyte |= ((openDr & 1) << 3);
  flagbyte |= ((outAL & 1) << 4);
  return flagbyte;
}
示例#2
0
int main(void) {
	init();

	while (1) {
		if (button_A_pressed) {
			can_broadcast(PADDLE_STATUS, &(uint8_t){1});
			button_A_pressed = false;
		}

		if (button_B_pressed) {
			can_broadcast(PADDLE_STATUS, &(uint8_t){0});
			button_B_pressed = false;
		}


		if (DIGITAL_READ(NEUTRAL_PORT, NEUTRAL_PIN) && (neutral_status == OFF)) {
			neutral_status = ON;
			_delay_ms(100);
			can_broadcast(NEUTRAL_ENABLED, &(uint8_t){1});
		} else if (!DIGITAL_READ(NEUTRAL_PORT, NEUTRAL_PIN) && (neutral_status == ON)) {
			neutral_status = OFF;
			_delay_ms(100);
			can_broadcast(NEUTRAL_ENABLED, &(uint8_t){0});
		}

		// new_state = 2 if front stop-button is pressed.
		// new_state = 1 if rear stop-button is pressed.
		const uint8_t new_state = (!DIGITAL_READ(PORTF, PIN5) * 1) + (!DIGITAL_READ(PORTF, PIN7) * 2);
		if (new_state != last_state) {
			last_state = new_state;
			can_broadcast(GEAR_STOP_BUTTON, &(uint8_t){new_state});
			_delay_ms(20);
		}
	}

	return 0;
}
示例#3
0
/* We disable interrupts while transfer a byte. This ensures that we execute
 * at nominal speed, in spite of aggressive USB polling.
 */
static _u8 ispBlockTransfer(_u8 *block, _u8 len)
{
    _u8   cnt, shift = 0, port, delay = ispClockDelay;

    /* minimum clock pulse width:
     * 5 + 4 * delay clock cycles           -> Tmin = 750 ns
     * total clock period: 12 + 8 * delay   -> fmax = 600 kHz
     */
    cli();
    while(len--){   /* len may be 0 */
        cnt = 8;
        shift = *block++;
        do{
            if(shift & 0x80){
                DIGITAL_WRITE(ISP_MOSI, HIGH);
            }else
            {
                DIGITAL_WRITE(ISP_MOSI, LOW);
            }
            sei();
            timerTicksDelay(delay);
            cli(); 
            DIGITAL_WRITE(ISP_SCK, HIGH);  /* <-- data clocked by device */
            shift <<= 1;

            if(DIGITAL_READ(ISP_MISO))  /* no driver in this hardware */
                shift |= 1;
            sei();
            timerTicksDelay(delay);
            cli();
            DIGITAL_WRITE(ISP_SCK, LOW);    /* <-- device changes data */
        }while(--cnt);
    }
    sei();
    return shift;
}
示例#4
0
void activeDigitalSend(uint8_t *outData, uint8_t *outLen, uint8_t *inband) {
  *outLen = 1;
  outData[0] = (~(DIGITAL_READ(IN0))) & 0x1;
}