static void writereg(uint8_t reg, uint8_t val) { ss(true); sendrecv(reg); sendrecv(val); ss(false); util_delay(100); }
static uint8_t readreg(uint8_t reg) { ss(true); sendrecv(reg | (1 << 7)); uint8_t val = sendrecv(0); ss(false); util_delay(100); return val; }
void us_trig(void) // Ultrasonic trigger, BLOCKING { US_PORT->DATA |= (1<<US_TRIG); //set PIO0_2 high util_delay(15); //"sleep" for 15 us (Pulse cannot be <10us!) US_PORT->DATA &= ~(1<<US_TRIG); //set PIO0_2 low while ((US_PORT->DATA & (1<<US_ECHO)) == 0); //while pulse is travelling us_counter = 0; // pulse is incoming, so we add 1 us_state = STATE_COUNTING; }
/* Wait a little */ void util_wait( void ) { util_delay(0, 10000000); } /* End of 'util_wait' function */
void hal_delay(delay) { util_delay(delay); }