void HCA700_wifi_power_on() { set_gpio_value(IO_PORT,WIFI_POWER_PIN, 1); }
void HCA700_DEBUG_LED_off() { set_gpio_value(IO_PORT,DEBUG_LED_PIN, 0); }
void HCA700_SD_card_power_off() { set_gpio_value(IO_PORT,SD_CARD_POWER_PIN, 1); }
void HCA700_WM8750_off() { set_gpio_value(IO_PORT,WM8750_CLOCK_PIN, 0); }
void HCA700_DEBUG_LED_on() { set_gpio_value(IO_PORT,DEBUG_LED_PIN, 1); }
void HCA700_USB_function_WIFI() { set_gpio_value(IO_PORT,USB_SWITCH_FUNCTION_PIN, 1); }
void HCA700_USB_function_NONE() { set_gpio_value(IO_PORT,USB_SWITCH_FUNCTION_PIN, 0); }
void HCA700_USB_switch_on() { set_gpio_value(IO_PORT,USB_SWITCH_EN_PIN, 0); }
/** * @brief Main program. * @param None * @retval None */ int main(int argc, char *argv[]) { int ret = 0; uint8_t *tx; uint8_t *rx; int size; int i; parse_opts(argc, argv); spi_fd = open(device, O_RDWR); if (spi_fd < 0) pabort("can't open device"); /* * spi mode */ ret = ioctl(spi_fd, SPI_IOC_WR_MODE32, &mode); if (ret == -1) pabort("can't set spi mode"); ret = ioctl(spi_fd, SPI_IOC_RD_MODE32, &mode); if (ret == -1) pabort("can't get spi mode"); /* * bits per word */ ret = ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) pabort("can't set bits per word"); ret = ioctl(spi_fd, SPI_IOC_RD_BITS_PER_WORD, &bits); if (ret == -1) pabort("can't get bits per word"); /* * max speed hz */ ret = ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) pabort("can't set max speed hz"); ret = ioctl(spi_fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); if (ret == -1) pabort("can't get max speed hz"); printf("spi mode: 0x%x\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); /* eMotionControl module initialization */ eMotionControl_Init(); /* Customize target stepper-motor specific registers at easySPIN module level */ /* TVAL register setup */ easySPIN_SetParam(easySPIN_TVAL, 0x00); /* T_FAST register setup */ easySPIN_SetParam(easySPIN_STEP_MODE, easySPIN_STEP_SEL_1 | easySPIN_SYNC_SEL_1_2); /* TON_MIN register setup */ easySPIN_SetParam(easySPIN_TON_MIN, 0x00); /* TOFF_MIN register setup */ easySPIN_SetParam(easySPIN_TOFF_MIN, 0x00); /* OCD_TH register setup */ easySPIN_SetParam(easySPIN_OCD_TH, easySPIN_OCD_TH_2625mA); /* STEP_MODE register setup */ easySPIN_SetParam(easySPIN_STEP_MODE, easySPIN_STEP_SEL_1 | easySPIN_SYNC_SEL_1_2); /* ALARM_EN register setup */ easySPIN_SetParam(easySPIN_ALARM_EN, easySPIN_ALARM_EN_OVERCURRENT | easySPIN_ALARM_EN_THERMAL_SHUTDOWN | easySPIN_ALARM_EN_THERMAL_WARNING | easySPIN_ALARM_EN_UNDERVOLTAGE | easySPIN_ALARM_EN_SW_TURN_ON | easySPIN_ALARM_EN_WRONG_NPERF_CMD); /* CONFIG register setup */ easySPIN_SetParam(easySPIN_CONFIG, easySPIN_CONFIG_INT_16MHZ | easySPIN_CONFIG_EN_TQREG_INT_REG | easySPIN_CONFIG_OC_SD_ENABLE | easySPIN_CONFIG_SR_180V_us | easySPIN_CONFIG_TSW_8_us); /* Read STATUS register */ easySPIN_rx_data = easySPIN_Get_Status(); // /* GoHome command example */ // eMotionControl_GoHome(); // eMotionControl_WaitWhileActive(); // currentPosition = easySPIN_GetParam(easySPIN_ABS_POS); // // /* GoTo command example */ // eMotionControl_GoTo(-65); // eMotionControl_WaitWhileActive(); // currentPosition = easySPIN_GetParam(easySPIN_ABS_POS); // // eMotionControl_GoTo(0); // eMotionControl_WaitWhileActive(); // currentPosition = easySPIN_GetParam(easySPIN_ABS_POS); // // eMotionControl_GoTo(65); // eMotionControl_WaitWhileActive(); // currentPosition = easySPIN_GetParam(easySPIN_ABS_POS); // // eMotionControl_GoTo(0); // eMotionControl_WaitWhileActive(); // currentPosition = easySPIN_GetParam(easySPIN_ABS_POS); // // /* Move command example */ // eMotionControl_Move(DIR_Forward, 200); // eMotionControl_WaitWhileActive(); // // eMotionControl_Move(DIR_Reverse, 200); // eMotionControl_WaitWhileActive(); // // /* Run command example */ // eMotionControl_Run(DIR_Forward, MAX_STEPS_PER_SEC); /* Wait few seconds - motor turns */ sleep(3); /* Enable easySPIN powerstage */ easySPIN_Enable(); set_gpio_value(easySPIN_DIR_GPIO,HIGH); for (i=0; i<1000; i++) { set_gpio_value(easySPIN_STCK_GPIO,(i%2)); usleep(1000); }; set_gpio_value(easySPIN_DIR_GPIO,LOW); for (i=0; i<1000; i++) { set_gpio_value(easySPIN_STCK_GPIO,(i%2)); usleep(1000); }; /* SoftStop command example */ //while(eMotionControl_GetState() != Steady); //eMotionControl_SoftStop(); //eMotionControl_WaitWhileActive(); /* Disable power stage */ easySPIN_Disable(); close(spi_fd); //while (1) // ; }
int main(int argc, char** argv){ //variable declarations struct pollfd fdset[1]; int nfds = 1; int timeout = 3000; int rc; char* buf[MAX_BUF]; int gpio1, gpio2; int gpio1_fd, gpio2_fd; int gpio2_value = 0; int pattern =0; int value =0; char *end; int res, i2cbus, address, size, file; int daddress; char filename[20]; //Setting the signal handler for Ctrl + C if (signal(SIGINT, signal_handler) == SIG_ERR) printf("\ncan't catch SIGINT\n"); //Argument checking for at least five if(argc < 6){ printf("Usage: %s <input-gpio> <output-gpio> <i2c-bus> <i2c-address> <register>\n", argv[0]); printf("polls input-gpio, and writes value to output-gpio\n"); fflush(stdout); return 1; } //Assigning gpio values gpio1 = atoi(argv[1]); gpio2 = atoi(argv[2]); //Input for Argument 1 export_gpio(gpio1); set_gpio_direction(gpio1, "in"); set_gpio_edge(gpio1, "falling"); gpio1_fd = gpio_fd_open(gpio1); //Output for Argument 2 export_gpio(gpio2); set_gpio_direction(gpio2, "out"); set_gpio_value(gpio2, gpio2_value); gpio2_fd = gpio_fd_open(gpio2); //Assigning I2C values i2cbus = atoi(argv[3]); address = atoi(argv[4]); daddress = atoi(argv[5]); size = I2C_SMBUS_BYTE; sprintf(filename, "/dev/i2c-%d", i2cbus); file = open(filename, O_RDWR); if (file<0) { if (errno == ENOENT) { fprintf(stderr, "Error: Could not open file " "/dev/i2c-%d: %s\n", i2cbus, strerror(ENOENT)); } else { fprintf(stderr, "Error: Could not open file " "`%s': %s\n", filename, strerror(errno)); if (errno == EACCES) fprintf(stderr, "Run as root?\n"); } exit(1); } if (ioctl(file, I2C_SLAVE, address) < 0) { fprintf(stderr, "Error: Could not set address to 0x%02x: %s\n", address, strerror(errno)); return -errno; } while(loop){ memset((void*)fdset, 0, sizeof(fdset)); fdset[0].fd = gpio1_fd; fdset[0].events = POLLPRI; rc = poll(fdset, nfds, timeout); if (rc < 0){ printf("\npoll() failed!\n"); } if (rc == 0){ printf("."); } if((fdset[0].revents & POLLPRI) == POLLPRI) { read(fdset[0].fd, buf, MAX_BUF); printf("interrupt value=%c\n", buf[0]); pattern++; if(pattern == 4){ pattern = 0; } } printf("Case %d\n",pattern); switch(pattern){ // Blink led case 0: if(gpio2_value){ gpio2_value = 0; } else{ gpio2_value = 1; } set_gpio_value(gpio2, gpio2_value); break; // PWM output for blinking LED by frequency and duty cycle case 1: set_mux_value("gpmc_a2",6); set_pwm("ehrpwm.1:0",10,25); break; // Analog In for reading Voltage from POT case 2: unset_pwm("ehrpwm.1:0"); value = read_ain("ain6"); printf("Voltage: %d\n",value); break; // I2C Device reading temperature from the sensor case 3: printf("Case 3\n"); res = i2c_smbus_write_byte(file, daddress); if (res < 0) { fprintf(stderr, "Warning - write failed, filename=%s, daddress=%d\n", filename, daddress); } res = i2c_smbus_read_byte_data(file, daddress); if (res < 0) { fprintf(stderr, "Error: Read failed, res=%d\n", res); exit(2); } printf("Temperature: %d°C\n", res); break; default: break; } } close(file); gpio_fd_close(gpio1_fd); gpio_fd_close(gpio2_fd); unexport_gpio(gpio1); unexport_gpio(gpio2); fflush(stdout); return 0; }
int main(int argc, char** argv){ //variable declarations struct pollfd fdset[1]; int nfds = 1; int timeout = 100; int rc; char* buf[MAX_BUF]; int gpio1, gpio2, gpio_count1, gpio_count2; int gpio1_fd, gpio2_fd; int gpio2_value = 0; int program = 0; int ain = 0; float duty_cycle = 0; int i2c_read; //check that at least two arguments are passed in if(argc < 3){ printf("Usage: %s <input-gpio> <output-gpio>\n", argv[0]); printf("polls input-gpio, and writes value to output-gpio\n"); fflush(stdout); return 1; } //set signal handler if (signal(SIGINT, signal_handler) == SIG_ERR) printf("\ncan't catch SIGINT\n"); //assign gpio values gpio1 = atoi(argv[1]); gpio2 = atoi(argv[2]); //argument 1 will be input export_gpio(gpio1); set_gpio_direction(gpio1, "in"); set_gpio_edge(gpio1, "falling"); gpio1_fd = gpio_fd_open(gpio1); //argument 2 will be output export_gpio(gpio2); set_gpio_direction(gpio2, "out"); set_gpio_value(gpio2, gpio2_value); gpio2_fd = gpio_fd_open(gpio2); //prepare gpio_count1 and gpio_count2 gpio_count1 = 30; gpio_count2 = 31; export_gpio(gpio_count1); export_gpio(gpio_count2); set_mux_value("gpmc_wait0",7); set_gpio_direction(gpio_count1, "out"); set_gpio_direction(gpio_count2, "out"); //prepare i2c bus int file; while(keepgoing){ memset((void*)fdset, 0, sizeof(fdset)); fdset[0].fd = gpio1_fd; fdset[0].events = POLLPRI; //fdset[1].fd = gpio2_fd; //fdset[1].events = POLLPRI; rc = poll(fdset, nfds, timeout); if (rc < 0){ printf("\npoll() failed!\n"); } if((fdset[0].revents & POLLPRI) == POLLPRI) { read(fdset[0].fd, buf, MAX_BUF); usleep(100); gpio2_value = ~(gpio2_value)&1; set_gpio_value(gpio2, gpio2_value); program++; if(program > 3) program = 0; set_gpio_value(gpio_count1, program & 1); set_gpio_value(gpio_count2, program & 2); } switch(program){ case 0: duty_cycle = read_ain("ain6"); duty_cycle = duty_cycle/4095 * 100; set_mux_value("gpmc_a2", 6); set_pwm("ehrpwm.1:0", 1000, (int) duty_cycle); break; case 1: ain = read_ain("ain6"); printf("ain5 = %d\n", ain); unset_pwm("ehrpwm.1:0"); break; case 2: unset_pwm("ehrpwm.1:0"); break; case 3: if((file = open("/dev/i2c-3", O_RDWR)) < 0){ printf("failed to open i2c-3 bus\n"); return 1; } if (ioctl(file, I2C_SLAVE, 72) < 0){ printf("Could not set address for i2c\n"); return 1; } i2c_read = i2c_smbus_read_byte_data(file, 0); close(file); printf("0x%02x (%d)\n", i2c_read, i2c_read); break; default: break; } } gpio_fd_close(gpio1_fd); gpio_fd_close(gpio2_fd); unexport_gpio(gpio1); unexport_gpio(gpio2); unexport_gpio(gpio_count1); unexport_gpio(gpio_count2); unset_pwm("ehrpwm.1:0"); set_mux_value("gpmc_a2", 7); fflush(stdout); return 0; }
int main(int argc, char *argv[]) { extern char *optarg; char *cptr; int gpio_value = 0; int nchannel = 0; int c; int i; opterr = 0; while ((c = getopt(argc, argv, "g:io:ck")) != -1) { switch (c) { case 'g': gl_gpio_base = (int)strtoul(optarg, &cptr, 0); if (cptr == optarg) usage(argv[0]); break; case 'i': gpio_opt = IN; break; case 'o': gpio_opt = OUT; gpio_value = (int)strtoul(optarg, &cptr, 0); if (cptr == optarg) usage(argv[0]); break; case 'c': gpio_opt = CYLON; break; case 'k': gpio_opt = KIT; break; case '?': usage(argv[0]); default: usage(argv[0]); } } if (gl_gpio_base == 0) { usage(argv[0]); } nchannel = open_gpio_channel(gl_gpio_base); signal(SIGTERM, signal_handler); /* catch kill signal */ signal(SIGHUP, signal_handler); /* catch hang up signal */ signal(SIGQUIT, signal_handler); /* catch quit signal */ signal(SIGINT, signal_handler); /* catch a CTRL-c signal */ switch (gpio_opt) { case IN: set_gpio_direction(gl_gpio_base, nchannel, "in"); gpio_value=get_gpio_value(gl_gpio_base, nchannel); fprintf(stdout,"0x%08X\n", gpio_value); break; case OUT: set_gpio_direction(gl_gpio_base, nchannel, "out"); set_gpio_value(gl_gpio_base, nchannel, gpio_value); break; case CYLON: #define CYLON_DELAY_USECS (10000) set_gpio_direction(gl_gpio_base, nchannel, "out"); for (;;) { for(i=0; i < ARRAY_SIZE(cylon); i++) { gpio_value=(int)cylon[i]; set_gpio_value(gl_gpio_base, nchannel, gpio_value); } usleep(CYLON_DELAY_USECS); } case KIT: #define KIT_DELAY_USECS (10000) set_gpio_direction(gl_gpio_base, nchannel, "out"); for (;;) { for (i=0; i<ARRAY_SIZE(kit); i++) { gpio_value=(int)kit[i]; set_gpio_value(gl_gpio_base, nchannel, gpio_value); } usleep(KIT_DELAY_USECS); } default: break; } close_gpio_channel(gl_gpio_base); return 0; }