void edge_detect_test(uint8_t pin, uint8_t mode) { switch(mode) { case LOW_MODE:/*low level detect*/ bcm2835_gpio_len(pin); printf("Start to detect the low level on the Phy07!\n"); while(1) { if(bcm2835_gpio_eds(pin)) { printf("Phy07:Low level has been detected !\n"); break; } } break; case HIGH_MODE:/*high level detect*/ bcm2835_gpio_hen(pin); printf("Start to detect the High level on the Phy07!\n"); while(1) { if(bcm2835_gpio_eds(pin)) { printf("Phy07:High level has been detected !\n"); break; } } break; case FALLING_MODE:/*falling detect*/ bcm2835_gpio_fen(pin); printf("Start to detect the falling on the Phy07!\n"); while(1) { if(bcm2835_gpio_eds(pin)) { printf("Phy07: Falling has been detected !\n"); break; } } break; case RISING_MODE:/*rising detect*/ bcm2835_gpio_ren(pin); printf("Start to detect the rising on the Phy07!\n"); while(1) { if(bcm2835_gpio_eds(pin)) { printf("Phy07:Rising has been detected !\n"); break; } } break; } }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO if (!bcm2835_init()) return 1; // Set RPI pin to be an input bcm2835_gpio_fsel(RF_IRQ_PIN, BCM2835_GPIO_FSEL_INPT); // with a puldown bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN); // And a rising edge detect enable bcm2835_gpio_ren(RF_IRQ_PIN); while (1) { // we got it ? if (bcm2835_gpio_eds(RF_IRQ_PIN)) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(RF_IRQ_PIN); printf("Rising event detect for pin GPIO%d\n", RF_IRQ_PIN); } // wait a bit bcm2835_delay(5); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Set RPI pin P1-15 to be an input bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT); // with a pullup bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP); // And a low detect enable bcm2835_gpio_len(PIN); while (1) { if (bcm2835_gpio_eds(PIN)) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(PIN); printf("low event detect for pin 15\n"); } // wait a bit delay(500); } bcm2835_close(); return 0; }
//uint8_t bcm2835_gpio_eds(uint8_t pin); /// Call bcm2835_gpio_eds with 1 parameter /// \par Refer /// \par Modify void ope_gpio_eds(void) { uint8_t ret; get_byte_code(); ret = bcm2835_gpio_eds( *((uint8_t *)(buff+1)) ); set_ope_code( OPE_GPIO_EDS ); set_byte_code( ret ); put_reply(); mark_sync(); }
/* Check for a detection, 0 if nothing was found, 1 motion detected */ int pirmtn_detected() { // Wait a little while, we don't wanna be to fast delay(500); if (bcm2835_gpio_eds(pirmtn_pin)) { // Now clear the eds flag by setting it to 1 pirmtn_reset(); return 1; } return 0; }
// this is a simple test program that prints out what it will do rather than // actually doing it int main(int argc, char **argv) { // Be non-destructive bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Configure some GPIO pins fo some testing // Set RPI pin P1-11 to be an output bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP); // Set RPI pin P1-15 to be an input bcm2835_gpio_fsel(RPI_GPIO_P1_15, BCM2835_GPIO_FSEL_INPT); // with a pullup bcm2835_gpio_set_pud(RPI_GPIO_P1_15, BCM2835_GPIO_PUD_UP); // And a low detect enable bcm2835_gpio_len(RPI_GPIO_P1_15); // and input hysteresis disabled on GPIOs 0 to 27 bcm2835_gpio_set_pad(BCM2835_PAD_GROUP_GPIO_0_27, BCM2835_PAD_SLEW_RATE_UNLIMITED|BCM2835_PAD_DRIVE_8mA); #if 1 // Blink while (1) { // Turn it on bcm2835_gpio_write(RPI_GPIO_P1_11, HIGH); // wait a bit bcm2835_delay(500); // turn it off bcm2835_gpio_write(RPI_GPIO_P1_11, LOW); // wait a bit bcm2835_delay(500); } #endif #if 0 // Read input while (1) { // Read some data uint8_t value = bcm2835_gpio_lev(RPI_GPIO_P1_15); printf("read from pin 15: %d\n", value); // wait a bit bcm2835_delay(500); } #endif #if 0 // Look for a low event detection // eds will be set whenever pin 15 goes low while (1) { if (bcm2835_gpio_eds(RPI_GPIO_P1_15)) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(RPI_GPIO_P1_15); printf("low event detect for pin 15\n"); } // wait a bit bcm2835_delay(500); } #endif if (!bcm2835_close()) return 1; return 0; }
/* ====================================================================== Function: main Purpose : not sure ;) Input : command line parameters Output : - Comments: - ====================================================================== */ int main (int argc, const char* argv[] ) { // LED blink ms timer saving unsigned long led_blink[NB_MODULES] = {0,0,0}; // caught CTRL-C to do clean-up signal(SIGINT, sig_handler); // Display app name printf( "%s\n", __BASEFILE__); for (uint8_t i=0; i<strlen(__BASEFILE__); i++) { printf( "="); } printf("\n"); // Init GPIO bcm if (!bcm2835_init()) { fprintf( stderr, "bcm2835_init() Failed\n\n" ); return 1; } //save driver instances pointer drivers[IDX_MOD1] = &rf95_1; drivers[IDX_MOD2] = &rf95_2; drivers[IDX_MOD3] = &rf69_3; // light onboard LEDs pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH); // configure all modules I/O CS pins to 1 before anything else // to avoid any problem with SPI sharing for (uint8_t i=0 ; i<NB_MODULES; i++) { // CS Ping as output and set to 1 pinMode(CSN_pins[i], OUTPUT); digitalWrite(CSN_pins[i], HIGH); } // configure all modules I/O pins for (uint8_t i=0 ; i<NB_MODULES; i++) { // configure all modules if (!initRadioModule(i)){ force_exit = true; } } // All init went fine, continue specific init if any if (!force_exit) { // Set all modules in receive mode rf95_1.setModeRx(); rf95_2.setModeRx(); rf69_3.setModeRx(); printf( "Listening for incoming packets...\n" ); } // Begin the main loop code // ======================== while (!force_exit) { // Loop thru modules for (uint8_t idx=0 ; idx<NB_MODULES ; idx++) { // Rising edge fired ? if (bcm2835_gpio_eds(IRQ_pins[idx])) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(IRQ_pins[idx]); //printf("Packet Received, Rising event detect for pin GPIO%d\n", IRQ_pins[idx]); // Start associated led blink led_blink[idx] = millis(); digitalWrite(LED_pins[idx], HIGH); getReceivedData(idx); } // has IRQ // A module led blink timer expired ? Light off if (led_blink[idx] && millis()-led_blink[idx]>LED_BLINK_MS) { led_blink[idx] = 0; digitalWrite(LED_pins[idx], LOW); } // Led timer expired getReceivedData(idx); } // For Modules // On board led blink (500ms off / 500ms On) digitalWrite(LED_PIN, (millis()%1000)<500?LOW:HIGH); // Let OS doing other tasks // For timed critical appliation receiver, you can reduce or delete // this delay, but this will charge CPU usage, take care and monitor bcm2835_delay(5); } // We're here because we need to exit, do it clean // Light off on board LED digitalWrite(LED_PIN, LOW); // All module LEDs off, all modules CS line High for (uint8_t i=0 ; i<NB_MODULES; i++) { digitalWrite(LED_pins[i], LOW); digitalWrite(CSN_pins[i], HIGH); } printf( "\n%s, done my job!\n", __BASEFILE__ ); bcm2835_close(); return 0; }
/** * @brief Checks fro even on given pin. * @param pin Pin to be configured, Available pin definitons are defined in the Utitlies.h * @return none */ unsigned char CheckPinforEvent(PIN_t pin) { unsigned char event = bcm2835_gpio_eds(pin); //Check for event detection bcm2835_gpio_set_eds(pin); //Clear even detection interrupt flags return event; }