本文整理汇总了C++中os_delay_us函数的典型用法代码示例。如果您正苦于以下问题:C++ os_delay_us函数的具体用法?C++ os_delay_us怎么用?C++ os_delay_us使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了os_delay_us函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hspi_cs_disable
/// @brief Initialize TFT
/// @return diplay ID 9341
MEMSPACE
window *tft_init(void)
{
TFT_RST_INIT; // RESET PIN
TFT_INIT; // DATA/COMMAND
TFT_CS_INIT; // CHIP SELLECT
hspi_cs_disable(TFT_CS_PIN);
// TFT_CS_DISABLE;
// Start with slow clock so tft_readId works
// This is the only function that fails at less then 1.
// tft_readId is the ONLY SPI bus command that needs this.
// Nomal reads work fine.
tft_spi_init(2);
TFT_RST_ACTIVE;
os_delay_us(10000);
TFT_RST_DEACTIVE;
os_delay_us(1000);
/* Adafruit 9341 TFT Display Initialization */
tft_configRegister();
/* Read the TFT ID value */
tft_ID = tft_readId();
// fast SPI
tft_spi_init(1);
/* Setup the master window */
tft_window_init(tft, TFT_XOFF, TFT_YOFF, TFT_W, TFT_H);
tft_setRotation(0);
tft_fillWin(tft, tft->bg);
return (tft);
}
示例2: dht11_read
int dht11_read(int gpio, int* temp, int* rh) {
unsigned int cs, expected_cs;
int max_cycles = 100000, thresh;
/* Get DHT11's attention. */
set_gpio(gpio, 0);
os_delay_us(20 * 1000);
/* Switch GPIO pin to input and let it stabilize. */
read_gpio_pin(gpio);
os_delay_us(1);
/* Starting with high, wait for first 80us of L. */
await_change(gpio, &max_cycles);
thresh = await_change(gpio, &max_cycles); /* First 80 us low. */
/* Then 80us of H. */
thresh += await_change(gpio, &max_cycles); /* Then 80 us high. */
if (max_cycles <= 0) return 0;
/* We use this to calibrate our delay: take average of the two
* and further divide by half to get number of cycles that represent 40us. */
thresh /= 4;
/* Now read the data. */
cs = (*rh = dht11_read_bits(gpio, 8, thresh, &max_cycles));
cs += dht11_read_bits(gpio, 8, thresh, &max_cycles); /* Always 0. */
cs += (*temp = dht11_read_bits(gpio, 8, thresh, &max_cycles));
cs += dht11_read_bits(gpio, 8, thresh, &max_cycles); /* Always 0. */
expected_cs = dht11_read_bits(gpio, 8, thresh, &max_cycles);
/* printf("%d %d %d==%d %d %d\r\n", *temp, *rh, cs, expected_cs, thresh,
* max_cycles); */
return (max_cycles > 0 && cs == expected_cs);
}
示例3: valveClose
/**
* close valve
*/
LOCAL void ICACHE_FLASH_ATTR valveClose(SleeperStateT* sleeperState)
{
// start generator, preset valve direction to close and wait for generator voltage to stablelize
GPIO_OUTPUT_SET(GENERATOR_GPIO, 1);
GPIO_OUTPUT_SET(OPEN_VALVE_GPIO, 1); // 1 -> VOUT2 = H
os_delay_us(5000); // 5 ms -> us
// close valve by enabling H-bridge
GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 1);
os_delay_us(62500); // 62.5 ms -> us
// short circuit valve current
GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 0);
os_delay_us(1000); // 1 ms -> us
// done, go to passive state
valveDriverShutdown();
// update state
sleeperState->rtcMem.valveOpen = false;
if (now > sleeperState->rtcMem.valveOpenTime)
{
sleeperState->rtcMem.totalOpenDuration += (now - sleeperState->rtcMem.valveOpenTime)/1000;
}
ets_uart_printf("valveClose\r\n");
}
示例4: valveOpen
/**
* open valve
*/
LOCAL void ICACHE_FLASH_ATTR valveOpen(SleeperStateT* sleeperState)
{
// start generator, preset valve direction to open and wait for generator voltage to stablelize
GPIO_OUTPUT_SET(GENERATOR_GPIO, 1);
GPIO_OUTPUT_SET(OPEN_VALVE_GPIO, 0); // 0 -> VOUT1 = H
os_delay_us(5000); // 5 ms -> us
// open valve by enabling H-bridge
GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 1);
os_delay_us(VALVE_OPEN_PULSE_DURATION); // (250 ms) -> us
// short circuit valve current
GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 0);
os_delay_us(1000); // 1 ms -> us
// done, go to passive state
valveDriverShutdown();
// update state
if (!sleeperState->rtcMem.valveOpen)
{
sleeperState->rtcMem.valveOpen = true;
sleeperState->rtcMem.totalOpenCount++;
}
sleeperState->rtcMem.valveOpenTime = now;
ets_uart_printf("valveOpen\r\n");
}
示例5: ws2812_writergb
// Byte triples in the buffer are interpreted as R G B values and sent to the hardware as G R B.
int ICACHE_FLASH_ATTR ws2812_writergb(uint8_t gpio, char *buffer, size_t length)
{
// Initialize the output pin:
pinMode(gpio, OUTPUT);
digitalWrite(gpio, 0);
// Ignore incomplete Byte triples at the end of buffer:
length -= length % 3;
// Rearrange R G B values to G R B order needed by WS2812 LEDs:
size_t i;
for (i = 0; i < length; i += 3) {
const char r = buffer[i];
const char g = buffer[i + 1];
buffer[i] = g;
buffer[i + 1] = r;
}
// Do not remove these:
os_delay_us(1);
os_delay_us(1);
// Send the buffer:
ets_intr_lock();
const char * const end = buffer + length;
while (buffer != end) {
uint8_t mask = 0x80;
while (mask) {
(*buffer & mask) ? send_ws_1(gpio) : send_ws_0(gpio);
mask >>= 1;
}
++buffer;
}
ets_intr_unlock();
}
示例6: ws2812_writegrb
// Byte triples in the buffer are interpreted as G R B values and sent to the hardware as G R B.
int ICACHE_FLASH_ATTR ws2812_writegrb(uint8_t gpio, char *buffer, size_t length)
{
// Initialize the output pin:
pinMode(gpio, OUTPUT);
digitalWrite(gpio, 0);
// Ignore incomplete Byte triples at the end of buffer:
length -= length % 3;
// Do not remove these:
os_delay_us(1);
os_delay_us(1);
// Send the buffer:
ets_intr_lock();
const char * const end = buffer + length;
while (buffer != end) {
uint8_t mask = 0x80;
while (mask) {
(*buffer & mask) ? send_ws_1(gpio) : send_ws_0(gpio);
mask >>= 1;
}
++buffer;
}
ets_intr_unlock();
}
示例7: onewire_reset
// Perform the onewire reset function. We will wait up to 250uS for
// the bus to come high, if it doesn't then it is broken or shorted
// and we return a 0;
// Returns 1 if a device asserted a presence pulse, 0 otherwise.
uint32 ICACHE_FLASH_ATTR onewire_reset() {
uint32 result;
uint8 retries = 125;
// Disable output on the pin.
GPIO_DIS_OUTPUT(ONEWIRE_PIN);
// Wait for the bus to get high (which it should because of the pull-up resistor).
do {
if (--retries == 0) {
return 0;
}
os_delay_us(2);
} while (!GPIO_INPUT_GET(ONEWIRE_PIN));
// Transmit the reset pulse by pulling the bus low for at least 480 us.
GPIO_OUTPUT_SET(ONEWIRE_PIN, 0);
os_delay_us(500);
// Release the bus, and wait, then check for a presence pulse, which should start 15-60 us after the reset, and will last 60-240 us.
// So 65us after the reset the bus must be high.
GPIO_DIS_OUTPUT(ONEWIRE_PIN);
os_delay_us(65);
result = !GPIO_INPUT_GET(ONEWIRE_PIN);
// After sending the reset pulse, the master (we) must wait at least another 480 us.
os_delay_us(490);
return result;
}
示例8: lservo_pulse
//******************************************
// Servo pulse on multiple pins
// call this from tmr about every 20ms
// Lua: servo.pulse(reduce_each_by_us,reduce_first_by_us)
static int lservo_pulse( lua_State* L )
{
int i,d,d1;
d1=servo_reduce_first_by_us;
uint32_t tt[MAX_NUM_SERVOS],t1;
for(i=servo_min;i<MAX_NUM_SERVOS;i++){
platform_gpio_write(servo_pin[i], 1);
tt[i]=system_get_time();
os_delay_us(DELAY_SHIFT);
}
for(i=servo_min;i<MAX_NUM_SERVOS;i++){
t1=system_get_time();
d = servo_delay[i]+tt[i]-t1-servo_reduce_each_by_us-d1;
d1=0;
os_delay_us(d);
platform_gpio_write(servo_pin[i], 0);
tt[i]-=system_get_time();
}
if(servo_stats){
lua_newtable(L);
for(i=servo_min;i<MAX_NUM_SERVOS;i++){
lua_pushinteger( L, servo_pin[i] );
lua_pushinteger( L, tt[i] );
lua_settable(L, -3);
}
return 1;
} else return 0;
}
示例9: user_init
/**
* The main entry point in an ESP8266 application.
* It is where the logic of ESP8266 starts.
*/
void user_init() {
system_timer_reinit(); // use microsecond os_timer_*
// Initialize the UART devices
int defaultBaudRate = 9600;
#ifdef DEFAULT_CONSOLE_BAUDRATE
defaultBaudRate = DEFAULT_CONSOLE_BAUDRATE;
#endif
uart_init(defaultBaudRate, defaultBaudRate);
//uart_init(BIT_RATE_9600, BIT_RATE_9600);
os_delay_us(1000); // make sure there's a gap on uart output
UART_SetPrintPort(1);
system_set_os_print(1);
os_printf("\n\n\n\n");
os_delay_us(1000);
// Dump the restart exception information.
dumpRestart();
os_printf("Heap: %d\n", system_get_free_heap_size());
os_printf("Variables: %d @%dea = %dbytes\n", JSVAR_CACHE_SIZE, sizeof(JsVar),
JSVAR_CACHE_SIZE * sizeof(JsVar));
os_printf("Time sys=%u rtc=%u\n", system_get_time(), system_get_rtc_time());
// Register the ESP8266 initialization callback.
system_init_done_cb(initDone);
os_timer_setfn(&mainLoopSuspendTimer, enableMainLoop, NULL);
}
示例10: i2c_readByte
/**
* Receive byte from the I2C bus
* returns the byte
*/
uint8 ICACHE_FLASH_ATTR
i2c_readByte(void)
{
uint8 data = 0;
uint8 data_bit;
uint8 i;
i2c_sda(1);
for (i = 0; i < 8; i++)
{
os_delay_us(I2C_SLEEP_TIME);
i2c_sck(0);
os_delay_us(I2C_SLEEP_TIME);
i2c_sck(1);
os_delay_us(I2C_SLEEP_TIME);
data_bit = i2c_read();
os_delay_us(I2C_SLEEP_TIME);
data_bit <<= (7 - i);
data |= data_bit;
}
i2c_sck(0);
os_delay_us(I2C_SLEEP_TIME);
return data;
}
示例11: servo_timer_tick
servo_timer_tick(void) // servo timer function
{
unsigned char i;
os_timer_disarm(&servo_timer); // dis_arm the timer
os_timer_setfn(&servo_timer, (os_timer_func_t *)servo_timer_tick, NULL); // set the timer function, dot get os_timer_func_t to force function convert
os_timer_arm(&servo_timer, 20, 1); // arm the timer every 20ms and repeat
if (need_sort != 0) { sort_pulse_time(); }
// if only 1 servo is active
if (active_servos == 1)
{
DIRECT_WRITE_HIGH(servo_pin_sorted[0]);
os_delay_us(servo_delay_time[0]);
DIRECT_WRITE_LOW(servo_pin_sorted[0]);
}
// if more than 1 servo is active, loop for all active servo is needed
else if (active_servos > 1)
{
for ( i = 0 ; i < active_servos ; i++ )
{
if (servo_pin_sorted[i] >= 0) {DIRECT_WRITE_HIGH(servo_pin_sorted[i]);}
}
for ( i = 0 ; i < active_servos ; i++ )
{
if (servo_delay_time[i] > 0) {os_delay_us(servo_delay_time[i]);}
if (servo_pin_sorted[i] >= 0) {DIRECT_WRITE_LOW(servo_pin_sorted[i]);}
}
}
}
示例12: LCD_pulseEnable
void LCD_pulseEnable(uint8 _data){
LCD_expanderWrite(_data | En); // En high
os_delay_us(1); // enable pulse must be >450ns
LCD_expanderWrite(_data & ~En); // En low
os_delay_us(50); // commands need > 37us to settle
}
示例13: io_powerkeep_release
void ICACHE_FLASH_ATTR io_powerkeep_release() {
powerholdCount--;
os_printf("Powerdown hold count: %d\n", powerholdCount);
if (powerholdCount<=0) {
//Okay, we're done; release power.
os_printf("Powering down.\n");
UART_WaitTxFifoEmpty(0, 5000);
//This should disable PWM, which is needed to set the nightlight.
io_rgbled_set_color(0,0,0);
os_delay_us(10000);
//Set nightlight to on or off.
//ToDo: Read the enable value from flash config area. Is now hardcoded to on.
enableNightlight(0);
//Make GPIO0 high, to lower the chance of the ESP booting up in programming mode next time.
gpio_output_set((1<<0), 0, (1<<0), 0);
#if NEW_BUTTON
//Software fix for hardware problem... sometimes GPIO12 (=USB power detect) will mysteriously
//keep leaking power into the LDO enable input. Force low for a while to stop this from happening.
gpio_output_set(0, (1<<12), (1<<12), 0);
os_delay_us(1000);
gpio_output_set(0, (1<<12), 0, (1<<12));
#endif
//Kill power.
gpio_output_set(0, (1<<HOLD_PIN), (1<<HOLD_PIN), 0);
//We should be dead now. If not, getting killed by the wdt may be a good idea anyway.
while(1);
}
}
示例14: dmx_task
void ICACHE_FLASH_ATTR dmx_task(os_event_t *events) {
int i;
if(twinkl_has_changes()) {
INFO("Updating DMX channels\n");
twinkl_render(dmx_channels);
}
//INFO("Sending DMX channels\n");
//Space for break
PIN_FUNC_SELECT(pin_mux[dmx_tx_pin], FUNC_GPIO2);
gpio_output_set(0, BIT2, BIT2, 0);
os_delay_us(125);
//Mark After Break
gpio_output_set(BIT2, 0, BIT2, 0);
os_delay_us(50);
//Looks the wrong way round, but reduces jitter somehow
//Do not touch.
PIN_FUNC_SELECT(pin_mux[dmx_tx_pin], FUNC_U1TXD_BK);
uart_tx_one_char(1, 0);
for(i = 0; i < TWINKL_CHANNEL_COUNT; i++) {
uart_tx_one_char(1, dmx_channels[i]);
}
//INFO("Done sending DMX channels\n");
if(udp_server != NULL) {
os_timer_arm(&dmx_update_timer, dmx_refresh_delay, 0);
}
}
示例15: pcf8574_hd44780_write
DHI2C_STATUS ICACHE_FLASH_ATTR pcf8574_hd44780_write(int sda, int scl, const char *text, unsigned int len) {
DHI2C_STATUS status;
int i;
const static char init_data[] = {
0b00101100, // function set
0b00001100, // display on
0b00000001, // cursor clear
0b00000110 // entry mode set
};
// clear enable
if((status = pcf8574_set(sda, scl, ~((char)(PIN_E | PIN_RW)))) != DHI2C_OK)
return status;
// initialization
for(i = 0; i < 3; i++) {
if((status = pcf8574_hd44780_write_half(sda, scl, 0b0011, 1)) != DHI2C_OK)
return status;
os_delay_us(5000);
}
if((status = pcf8574_hd44780_write_half(sda, scl, 0b0010, 1)) != DHI2C_OK)
return status;
os_delay_us(100);
// configure
for(i = 0; i < sizeof(init_data); i++) {
if((status = pcf8574_hd44780_write_byte(sda, scl, init_data[i], 1)) != DHI2C_OK)
return status;
os_delay_us(2000);
}
int line = 0;
int ch = 0;
// write text to display RAM
for(i = 0; i < len; i++) {
int nla = text[i] == '\n';
int nlc = (i + 1 < len) ? (text[i] == '\\' && text[i + 1] == 'n') : 0;
if(ch == 20 || nla || nlc) {
line++;
if(ch == 20 && (nla || nlc))
line++;
if(line > 3)
break;
if((status = pcf8574_hd44780_set_line(sda, scl, line)) != DHI2C_OK)
return status;
ch = 0;
if(nlc)
i++;
if(nla || nlc)
continue;
}
if((status = pcf8574_hd44780_write_byte(sda, scl, text[i], 0)) != DHI2C_OK)
return status;
ch++;
}
return DHI2C_OK;
}