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; }
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; } }
static PyObject * PyBCM2835_gpio_len(PyObject *self, PyObject *args) { uint8_t pin; if (!PyArg_ParseTuple(args,"i",&pin)) { return NULL; } bcm2835_gpio_len(pin); Py_RETURN_NONE; }
// 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; }
//void bcm2835_gpio_len(uint8_t pin); /// Call bcm2835_gpio_len with 1 parameter /// \par Refer /// \par Modify void ope_gpio_len(void) { get_byte_code(); bcm2835_gpio_len( *((uint8_t *)(buff+1)) ); }