int wiringOliSetup() { initialiseEpoch() ; int result; result = sunxi_gpio_init(); if(result == SETUP_DEVMEM_FAIL) { printf("No access to /dev/mem. Try running as root !"); return SETUP_DEVMEM_FAIL; } else if(result == SETUP_MALLOC_FAIL) { printf("No memory !"); return SETUP_MALLOC_FAIL; } else if(result == SETUP_MMAP_FAIL) { printf("Mmap failed on module import"); return SETUP_MMAP_FAIL; } else { return SETUP_OK; } return SETUP_OK; }
int init_lcd_pin_direction() { // GPIO2 LCD // 1 +5V -> 2 VDD // 2 Ground -> 1 GND // // 3 +3.3V EMPTY // 4 Ground EMPTY // // // 5 PB0 (TWI0-SCK) -> 4 RS // 6 PG11 (USBH_EN) -> 5 R/W // 7 PB1 (TWI0-SDA) -> 6 E // // 8 PG10 (VGA_DIS) -> 7 DB0 // 10 PG9 (LED1) -> 8 DB1 // 11 PB3 -> 9 DB2 // 12 PE11 -> 10 DB3 // 13 PB4 -> 11 DB4 // 14 PE10 -> 12 DB5 // 16 PE9 -> 13 DB6 // 18 PE8 -> 14 DB7 // 9 PB2 (PWM0) ERROR // 15 PB10 ERROR // 17 PB15 (TWI1-SCK) ERROR int ret; //init gpio ret = sunxi_gpio_init(); if(ret) { printf("sunxi_gpio_init ERROR\n"); return -1; } /* //RS, R/W, E sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUNXI_GPIO_OUTPUT); //DB0 - DB7 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPG(9), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPB(3), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPE(11), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPB(4), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPE(10), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPE(9), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPE(8), SUNXI_GPIO_OUTPUT); */ sunxi_gpio_set_cfgpin(SUNXI_GPA(0), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPA(1), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUNXI_GPIO_OUTPUT); sunxi_gpio_set_cfgpin(SUNXI_GPG(9), SUNXI_GPIO_OUTPUT); return 0; }
/** * * Make initial initialization of the extention. This is done by map physical * memory to the virtual and thus gaining access to the memory. From there we * can do anything. * * @return none */ static PyObject* py_init(PyObject* self, PyObject* args) { if(sunxi_gpio_init() < 0){ return PyErr_SetFromErrno(PyExc_IOError); } Py_RETURN_NONE; }
void main (int argc, char **argv) { int pulseDelay=1000; if (argc >= 2) { pulseDelay = atoi(argv[1]); } printf("%d", pulseDelay); fflush(stdout); //return; // We'll operate on the currently running thread. pthread_t this_thread = pthread_self(); // struct sched_param is used to store the scheduling priority struct sched_param params; // We'll set the priority to the maximum. params.sched_priority = sched_get_priority_max(SCHED_FIFO); // Attempt to set thread real-time priority to the SCHED_FIFO policy int ret = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); if (ret != 0) { // Print the error //std::cout << "Unsuccessful in setting thread realtime prio" << std::endl; return; } sunxi_gpio_init(); sunxi_gpio_set_cfgpin(SERVO_PIN, PIN_OUTPUT); int callpointer = sunxi_gpio_getCallPointer(SERVO_PIN); int pindef = sunxi_gpio_getPindef(SERVO_PIN); const long frameLenght = 1000 * NANO_SECOND_MULTIPLIER; struct timespec onInterval = {0}; struct timespec offInterval = {0}; onInterval.tv_nsec = pulseDelay * 1000; //sunxi_gpio_output(SERVO_PIN, 1); /* while(1){ */ int i; struct timeval tStart, tStop, tLen; //for(i = 0;i<50;i++){ while(1){ gettimeofday (&tStart, NULL) ; sunxi_gpio_setFastOn(callpointer,pindef); // Berechnen wie lang man den Pulse einschalten sollte: gettimeofday (&tStop, NULL); timersub(&tStop,&tStart,&tLen); onInterval.tv_nsec = pulseDelay * 1000;; onInterval.tv_nsec -= tLen.tv_usec * 1000 ; nanosleep(&onInterval, NULL); sunxi_gpio_setFastOff(callpointer,pindef); //sunxi_gpio_output(SERVO_PIN, 0); // Berechnen wie lang noch schlafen: gettimeofday (&tStop, NULL); // TimesStop - TimeStart = TLen timersub(&tStop,&tStart,&tLen); offInterval.tv_nsec = frameLenght; offInterval.tv_nsec -= tLen.tv_usec * 1000 ; nanosleep(&offInterval, NULL); //return; // //nanosleep(&offInterval, NULL); } }