void gpio_write(gpio_t pin, int value) { if (value) { gpio(pin)->DATA |= _pin_mask(pin); } else { gpio(pin)->DATA &= ~_pin_mask(pin); } }
unsigned char dsInit() { gpio(); // P0_6 used as GPIO function outputMode(); // output mode pullUp(); // pull-up oneWireReset(); return oneWireCheck(); }
int main(int argc, char **argv) { int ret; ret = usart(argc-1,argv); //(+sizeof(char *)); if(ret < 0) return ret; ret = led(); if(ret < 0) return ret; ret = gpio(); return ret; }
void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over) { assert(pin != GPIO_UNDEF); IOC->OVER[_pp_num(pin)] = over; if (over != GPIO_OUT) { IOC->PINS[sel] = _pp_num(pin); } else { IOC->SEL[_pp_num(pin)] = sel; } /* enable alternative function mode */ gpio(pin)->AFSEL |= _pin_mask(pin); }
int gpio_init(gpio_t pin, gpio_mode_t mode) { /* check if mode is valid */ if (mode == MODE_NOTSUP) { return -1; } DEBUG("GPIO %"PRIu32", PORT: %u, PIN: %u\n", (uint32_t)pin, _port_num(pin), _pin_num(pin)); /* disable any alternate function and any eventual interrupts */ gpio(pin)->IE &= ~_pin_mask(pin); gpio(pin)->AFSEL &= ~_pin_mask(pin); /* configure pull configuration */ IOC->OVER[_pp_num(pin)] = mode; /* set pin direction */ if (mode == GPIO_OUT) { gpio(pin)->DIR |= _pin_mask(pin); } else { gpio(pin)->DIR &= ~_pin_mask(pin); } return 0; }
void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func) { assert(pin != GPIO_UNDEF); /* configure pin function and multiplexing */ if (over != GPIO_MUX_NONE) { IOC->OVER[_pp_num(pin)] = over; } if (sel != GPIO_MUX_NONE) { IOC->SEL[_pp_num(pin)] = sel; } if (func != GPIO_MUX_NONE) { IOC->PINS[func] = _pp_num(pin); } /* enable alternative function mode */ gpio(pin)->AFSEL |= _pin_mask(pin); }
// can be re-applied // doesn't support GPIO16 void STC_FLASHMEM ConfigurationManager::applyGPIO() { // GPIO for (uint32_t i = 0; i < 17; ++i) { bool configured, isOutput, pullUp, value; getGPIOParams(i, &configured, &isOutput, &pullUp, &value); if (configured) { // GPIO0..15 GPIO gpio(i); if (isOutput) gpio.modeOutput(); else gpio.modeInput(); gpio.enablePullUp(pullUp); if (isOutput) gpio.write(value); } } }
/** * Create a new instance of ServoControllerDummy and * set it to the private variable */ void dashee::test::ServoUART::setUp() { this->fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY); if (this->fd == -1) CPPUNIT_FAIL("Cannot open file!"); struct termios options; tcgetattr(this->fd, &options); cfsetispeed(&options, B230400); cfsetospeed(&options, B230400); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; // no flow control options.c_cflag &= ~CRTSCTS; options.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines options.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw options.c_oflag &= ~OPOST; // make raw // see: http://unixwiz.net/techtips/termios-vmin-vtime.html options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; if (tcsetattr(this->fd, TCSANOW, &options) < 0) CPPUNIT_FAIL("Initilizing UART failed"); // Reset the GPIO pin dashee::GPIO gpio(18, dashee::GPIO::OUT); gpio.low(); gpio.high(); // Important dashee::sleep(10000); this->servo = new dashee::ServoUART(&this->fd, 2); }
// Called during bootloader initialization void Chip_setup() { // Disable WDT WDT->WDT_MR = WDT_MR_WDDIS; // Enable Debug LED const GPIO_Pin debug_led = gpio(B,0); GPIO_Ctrl( debug_led, GPIO_Type_DriveSetup, GPIO_Config_None ); GPIO_Ctrl( debug_led, GPIO_Type_DriveHigh, GPIO_Config_None ); // Initialize non-volatile storage storage_init(); // Make sure USB transceiver is reset (in case we didn't do a full reset) udc_stop(); // Start USB stack udc_start(); }
cell pawn_gpio( AMX * amx, const cell * params ) { (void)amx; cell res = gpio( params[1] ); return res; }
int main(int argc, char *argv[]) { // Wait for keyboard to appear before displaying anything KeyDetection::waitForKeyboard(); QFile f("/sys/module/bcm2708/parameters/boardrev"); f.open(f.ReadOnly); int rev = f.readAll().trimmed().toInt(); f.close(); qDebug() << "Board revision is " << rev; int gpioChannel; if (rev == 2 || rev == 3) gpioChannel = 0; else gpioChannel = 2; QApplication a(argc, argv); RightButtonFilter rbf; GpioInput gpio(gpioChannel); bool runinstaller = false; bool gpio_trigger = false; bool keyboard_trigger = true; bool force_trigger = false; QString defaultLang = "en"; QString defaultKeyboard = "gb"; QString defaultDisplay = "0"; QString defaultPartition = "800"; // Process command-line arguments for (int i=1; i<argc; i++) { // Flag to indicate first boot if (strcmp(argv[i], "-runinstaller") == 0) runinstaller = true; // Enables use of GPIO 3 to force NOOBS to launch by pulling low else if (strcmp(argv[i], "-gpiotriggerenable") == 0) gpio_trigger = true; // Disables use of keyboard to trigger recovery GUI else if (strcmp(argv[i], "-keyboardtriggerdisable") == 0) keyboard_trigger = false; // Forces display of recovery GUI every time else if (strcmp(argv[i], "-forcetrigger") == 0) force_trigger = true; // Allow default language to be specified in commandline else if (strcmp(argv[i], "-lang") == 0) { if (argc > i+1) defaultLang = argv[i+1]; } // Allow default keyboard layout to be specified in commandline else if (strcmp(argv[i], "-kbdlayout") == 0) { if (argc > i+1) defaultKeyboard = argv[i+1]; } // Allow default display mode to be specified in commandline else if (strcmp(argv[i], "-dispmode") == 0) { if (argc > i+1) defaultDisplay = --argv[i+1]; } // Allow default boot partition to be specified in commandline else if (strcmp(argv[i], "-partition") == 0) { if (argc > i+1) defaultPartition = argv[i+1]; } } // Intercept right mouse clicks sent to the title bar a.installEventFilter(&rbf); #ifdef Q_WS_QWS QWSServer::setCursorVisible(false); #endif // Set wallpaper and icon, if we have resource files for that if (QFile::exists(":/icons/raspberry_icon.png")) a.setWindowIcon(QIcon(":/icons/raspberry_icon.png")); #ifdef Q_WS_QWS QWSServer::setBackground(BACKGROUND_COLOR); #endif QSplashScreen *splash = new QSplashScreen(QPixmap(":/wallpaper.png")); splash->show(); QApplication::processEvents(); // If -runinstaller is not specified, only continue if SHIFT is pressed, GPIO is triggered, // or no OS is installed (/dev/mmcblk0p5 does not exist) bool bailout = !runinstaller && !force_trigger && !(gpio_trigger && (gpio.value() == 0 )) && !(keyboard_trigger && KeyDetection::isF10pressed()) && QFile::exists(FAT_PARTITION_OF_IMAGE); // Keyboard detection done, load normal hid driver //QProcess::execute("/sbin/modprobe usbhid"); // Default to booting first extended partition putFileContents("/sys/module/bcm2708/parameters/reboot_part", "5\n"); if (bailout) { splash->hide(); reboot_to_extended(defaultPartition, true); } #ifdef Q_WS_QWS QWSServer::setCursorVisible(true); #endif // Main window in the middle of screen MainWindow mw(defaultDisplay, splash); mw.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, mw.size(), a.desktop()->availableGeometry())); mw.show(); #ifdef ENABLE_LANGUAGE_CHOOSER // Language chooser at the bottom center LanguageDialog* ld = new LanguageDialog(defaultLang, defaultKeyboard); ld->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignHCenter | Qt::AlignBottom, ld->size(), a.desktop()->availableGeometry())); ld->show(); #endif a.exec(); reboot_to_extended(defaultPartition, false); return 0; }
// Called early-on during ResetHandler void Chip_reset() { // Generating Secure Key print( "Generating Secure Key..." NL ); // Read current 64 bit secure number Chip_secure1 = GPBR_SECURE1; Chip_secure2 = GPBR_SECURE2; // Generate 64 bit random numbers while ( !rand_available() ); GPBR_SECURE1 = rand_value32(); while ( !rand_available() ); GPBR_SECURE2 = rand_value32(); // Disable rand generation rand_disable(); // Secure indicator string (lsusb), iInterface uint16_t *indicator_string = dfu_device_str_desc[4]->bString; uint16_t replacement = u' '; // Replace with space in secure mode // If using an external reset, disable secure validation // Or if the flash is blank if ( // PIN (External Reset Pin/Switch) (REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) == RSTC_SR_RSTTYP_UserReset // WDOG (Watchdog timeout) || (REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) == RSTC_SR_RSTTYP_WatchdogReset // Blank flash check || _app_rom == 0xffffffff || (Chip_secure1 == 0 && Chip_secure2 == 0) ) { print( "Secure Key Bypassed." NL ); Chip_secure1 = 0; Chip_secure2 = 0; // Replace with \0 to hide part of string replacement = u'\0'; } // Modify iInterface delimiter for ( uint8_t pos = 0; indicator_string[ pos ] != u'\0'; pos++ ) { // Looking for | character if ( indicator_string[ pos ] == u'|' ) { indicator_string[ pos ] = replacement; // If shortening, also change length if ( replacement == u'\0' ) { dfu_device_str_desc[4]->bLength = pos * 2 + 2; } } } print( "Secure Key Generated." NL ); // Make sure debug LED is off const GPIO_Pin debug_led = gpio(B,0); GPIO_Ctrl( debug_led, GPIO_Type_DriveSetup, GPIO_Config_None ); GPIO_Ctrl( debug_led, GPIO_Type_DriveLow, GPIO_Config_None ); }
void PictureSource::turn_on() { GPIO gpio(GPIO_port); gpio.set_high(); }
int gpio_read(gpio_t pin) { return (int)(gpio(pin)->DATA & _pin_mask(pin)); }
// Compiler Includes #include <Lib/ScanLib.h> // Project Includes #include <cli.h> #include <led.h> #include <print.h> #include <matrix_scan.h> #include <matrix_setup.h> #include <macro.h> // Local Includes #include "scan_loop.h" const GPIO_Pin ledCaps = gpio(E, 0); const GPIO_Pin ledFn = gpio(C, 11); const GPIO_Pin ledNum = gpio(C, 10); // ----- Function Declarations ----- // CLI Functions void cliFunc_echo( char* args ); extern uint8_t Matrix_pin( GPIO_Pin gpio, Type type ); // ----- Variables ----- // Scan Module command dictionary
void PictureSource::turn_off() { GPIO gpio(GPIO_port); gpio.input(); }
void gpio_irq_disable(gpio_t pin) { gpio(pin)->IE &= ~_pin_mask(pin); }
int sc_main(int, char **) { MBWrapper cpu("MBWrapper"); Memory inst_ram("inst_ram", INST_RAM_SIZE); // Memory data_ram("data_ram", SRAM_SIZE); Bus bus("bus"); TIMER timer("timer", sc_core::sc_time(20, sc_core::SC_NS)); Vga vga("vga"); Intc intc("intc"); Gpio gpio("gpio"); sc_core::sc_signal<bool> timer_irq("timer_irq"); sc_core::sc_signal<bool> vga_irq("vga_irq"); sc_core::sc_signal<bool> cpu_irq("cpu_irq"); // Load the program in RAM soclib::common::Loader::register_loader("elf", soclib::common::elf_load); try { soclib::common::Loader loader("../software/cross/a.out"); loader.load(inst_ram.storage, 0, SOFT_SIZE); for (int i = 0; i < SOFT_SIZE / 4; i++) { inst_ram.storage[i] = uint32_be_to_machine(inst_ram.storage[i]); } } catch (soclib::exception::RunTimeError e) { std::cerr << "unable to load ELF file in memory:" << std::endl; std::cerr << e.what() << std::endl; abort(); } // initiators cpu.socket.bind(bus.target); vga.initiator(bus.target); // targets // bus.initiator(data_ram.target); bus.initiator(inst_ram.target); bus.initiator(vga.target); bus.initiator(timer.target); bus.initiator(gpio.target); bus.initiator(intc.target); // interrupts vga.irq(vga_irq); timer.irq(timer_irq); intc.in0(vga_irq); intc.in1(timer_irq); intc.out(cpu_irq); cpu.irq(cpu_irq); // port start addr size bus.map(inst_ram.target, INST_RAM_BASEADDR, INST_RAM_SIZE); // bus.map(data_ram.target, SRAM_BASEADDR, SRAM_SIZE); bus.map(vga.target, VGA_BASEADDR, VGA_SIZE); bus.map(gpio.target, GPIO_BASEADDR, GPIO_SIZE); bus.map(timer.target, TIMER_BASEADDR, TIMER_SIZE); bus.map(intc.target, INTC_BASEADDR, INTC_SIZE); // start the simulation sc_core::sc_start(); return 0; }
int main(int argc, char *argv[]) { GpioInput gpio(3); QApplication a(argc, argv); RightButtonFilter rbf; QString currentLangCode; bool runinstaller = false; // Process command-line arguments for (int i=1; i<argc; i++) { if (strcmp(argv[i], "-runinstaller") == 0) runinstaller = true; else if (strcmp(argv[i], "-lang") == 0) if (argc > i+1) currentLangCode = argv[++i]; } // Intercept right mouse clicks sent to the title bar a.installEventFilter(&rbf); #ifdef Q_WS_QWS QWSServer::setCursorVisible(false); // Set wallpaper and icon, if we have resource files for that if (QFile::exists(":/icons/raspberry_icon.png")) a.setWindowIcon(QIcon(":/icons/raspberry_icon.png")); //if (QFile::exists(":/wallpaper.png")) // { //#ifdef CENTER_BACKGROUND_IMAGE // Using QSplashScreen to get a centered background image QWSServer::setBackground(BACKGROUND_COLOR); QSplashScreen *splash = new QSplashScreen(QPixmap(":/wallpaper.png")); splash->show(); QApplication::processEvents(); //#else // Scale background image to fit screen // QRect dim = a.desktop()->availableGeometry(); // QWSServer::setBackground(QImage(":/wallpaper.png").scaled(dim.width(), dim.height())); //#endif // } // else // { // QWSServer::setBackground(BACKGROUND_COLOR); // } //#endif #endif // If -runinstaller is not specified, only continue if SHIFT is pressed, GPIO is triggered or no OS is installed (/dev/mmcblk0p6 does not exist) bool bailout = !runinstaller && gpio.value() != 0 && !KeyDetection::isF10pressed() && QFile::exists(FAT_PARTITION_OF_IMAGE); if (bailout) { reboot_to_extended(); //return 1; } // Keyboard detection done, load normal hid driver QProcess::execute("/sbin/modprobe usbhid"); #ifdef Q_WS_QWS QWSServer::setCursorVisible(true); #endif #ifdef ENABLE_LANGUAGE_CHOOSER // Language chooser at the bottom center LanguageDialog* ld = new LanguageDialog(¤tLangCode); ld->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignHCenter | Qt::AlignBottom, ld->size(), a.desktop()->availableGeometry())); ld->show(); #endif // Main window in the middle of screen MainWindow mw(¤tLangCode, splash, ld); mw.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, mw.size(), a.desktop()->availableGeometry())); mw.show(); a.exec(); reboot_to_extended(); return 0; }
void gpio_toggle(gpio_t pin) { gpio(pin)->DATA ^= _pin_mask(pin); }
void gpio_clear(gpio_t pin) { gpio(pin)->DATA &= ~_pin_mask(pin); }
void gpio_set(gpio_t pin) { gpio(pin)->DATA |= _pin_mask(pin); }
// Project Includes #include <Lib/gpio.h> // Local Includes #include "../device.h" #include "../debug.h" // ----- Defines ----- // ----- Variables ----- // Screen PWM const GPIO_Pin red_chan_screen = gpio(C,1); // Esc key strobe (S7) const GPIO_Pin strobe_pin = gpio(D,0); const GPIO_Pin sense_pin = gpio(D,1); // ----- Functions ----- // Called early-on during ResetHandler void Device_reset() { } // Called during bootloader initialization
int main (int argc, char ** argv) { if (argc != 3) { usage (); } #ifdef DEBUG_WIN_X if (fork() != 0) { printf ("Forked to background, exiting.\n"); exit (0); } #endif log_open (LOGPATH); int fill_color = gdTrueColorAlpha (100, 100, 100, gdAlphaTransparent / 2); int line_color = gdTrueColorAlpha (175, 175, 175, gdAlphaOpaque); int text_color = gdTrueColorAlpha (255, 255, 255, gdAlphaOpaque); FILE * img_out; int img_time; char img_filename[64]; gdImagePtr camera_1; gdImagePtr camera_2; gdImagePtr output; int numloops = 0; int fpstimer; double a1, a2; tolerance_file_t * tol; int alliance; tol = get_tolerance (TOLPATH); log_write ("Got tolerance values from %s.", TOLPATH); if (argv[1][0] == 98) { log_write ("Seeking blue targets."); alliance = ALLIANCE_BLUE; } else { log_write ("Seeking red targets."); alliance = ALLIANCE_RED; } char * jpeg_buff; char * jpeg_buff_2; int jpeg_buff_size; int jpeg_buff_size_2; int x, y; blob * cam1_green; blob * cam2_green; blob * cam1_red; blob * cam2_red; blob * target_blob; int loop_ctr; loop_ctr = 0; float lastfps; log_write ("Beginning main loop."); while (1) { #ifndef DISABLE_IMG output = gdImageCreateTrueColor (1280, 480); #endif #ifndef DEBUG_WIN log_write ("Getting first jpeg."); jpeg_buff = get_jpeg (CAM1, &jpeg_buff_size); if (jpeg_buff == NULL) { log_write ("First jpeg buffer is null!"); exit (1); } if (jpeg_buff_size <= 0) { log_write ("First jpeg buffer size is invalid!"); exit (1); } log_write ("First jpeg received. Size: %d", jpeg_buff_size); camera_1 = gdImageCreateFromJpegPtr (jpeg_buff_size, jpeg_buff); if (camera_1 == NULL) { log_write ("gdImageCreateFromJpegPtr () failed for jpeg 1!"); exit (1); } log_write ("Getting second jpeg."); jpeg_buff_2 = get_jpeg (CAM2, &jpeg_buff_size_2); if (jpeg_buff_2 == NULL) { log_write ("Second jpeg buffer is null!"); exit (1); } if (jpeg_buff_size_2 <= 0) { log_write ("Second jpeg buffer size is invalid!"); exit (1); } log_write ("Second jpeg received. Size: %d", jpeg_buff_size_2); camera_2 = gdImageCreateFromJpegPtr (jpeg_buff_size_2, jpeg_buff_2); if (camera_2 == NULL) { log_write ("gdImageCreateFromJpegPtr () failed for jpeg 2!"); exit (1); } #endif // !DEBUG_WIN #ifdef DEBUG_WIN img_out = fopen ("cam1.jpg", "rb"); camera_1 = gdImageCreateFromJpeg (img_out); fclose (img_out); img_out = fopen ("cam2.jpg", "rb"); camera_2 = gdImageCreateFromJpeg (img_out); fclose (img_out); if (camera_1 == NULL) { log_write ("Camera 1 image did not load properly."); exit (1); } if (camera_2 == NULL) { log_write ("Camera 2 image did not load properly."); exit (1); } #endif // DEBUG_WIN log_write ("Detecting blobs on camera 1."); cam1_red = find (camera_1, &(tol->cam1_red)); cam1_green = find (camera_1, &(tol->cam1_green)); log_write ("Detecting blobs on camera 2."); cam2_red = find (camera_2, &(tol->cam2_red)); cam2_green = find (camera_2, &(tol->cam2_green)); if ((target_blob = target (cam1_red, cam1_green, alliance)) != NULL) { if ((target_blob->center_x + 50) > 400) { log_write ("Sending left motor command."); gpio (59, GPIO_ON); gpio (58, GPIO_OFF); } else if ((target_blob->center_x + 50) < 240) { log_write ("Sending right motor command."); gpio (58, GPIO_ON); gpio (59, GPIO_OFF); } else { log_write ("Sending left & right motor commands."); gpio (58, GPIO_ON); gpio (59, GPIO_ON); } #ifndef DISABLE_IMG //print_blobs (camera_1, target_blob, 100, 100, 100); #endif free_blobs (target_blob); } else { log_write ("EE: No targets found."); } if (cam1_red != NULL && cam1_green != NULL) { log_write ("Blob detection completed. Building image."); #ifndef DISABLE_IMG print_blobs (camera_1, cam1_red, 200, 0, 0); //print_blobs (camera_2, cam2_red, 200, 0, 0); print_blobs (camera_1, cam1_green, 0, 180, 20); //print_blobs (camera_2, cam2_green, 0, 180, 20); #endif free_blobs (cam1_red); free_blobs (cam2_red); free_blobs (cam1_green); free_blobs (cam2_green); #ifndef DISABLE_IMG gdImageCopy (output, camera_1, 0, 0, 0, 0, 640, 480); gdImageCopy (output, camera_2, 640, 0, 0, 0, 640, 480); #endif /*gdImageFilledRectangle (output, 540, 340, 760, 450, fill_color); gdImageRectangle (output, 540, 340, 760, 450, line_color); time_t rawtime; time (&rawtime); char * time_str = ctime (&rawtime); time_str[strlen(time_str)-1] = '\0'; render_text (output, text_color, 550, 360, "%s", time_str); if (cam1_red != NULL && cam2_red != NULL) { render_text (output, text_color, 550, 375, "Left Centroid: 300, 424", cam1_red->center_x, cam1_red->center_y); render_text (output, text_color, 550, 390, "Right Centroid: 422, 233", cam2_red->center_x, cam2_red->center_y); a1 = image_angle (cam1_red->center_x); a2 = image_angle (cam2_red->center_x); render_text (output, text_color, 550, 405, "Left Angle: %f", a1 * (180/PI)); render_text (output, text_color, 550, 420, "Right Angle: %f", a2 * (180/PI)); render_text (output, text_color, 550, 435, "Depth: %f", find_depth (a1, a2)); }*/ #ifndef DISABLE_IMG img_time = time (NULL); snprintf (img_filename, sizeof (img_filename), "%s%s%d.jpg", OUTPATH, argv[2], img_time); log_write ("Image built. Writing to file: %s", img_filename); img_out = fopen (img_filename, "wb"); gdImageJpeg (output, img_out, 100); fclose (img_out); #endif } else { log_write ("EE: Some cams didn't detect red+green blobs."); } #ifndef DISABLE_IMG gdImageDestroy (output); #endif gdImageDestroy (camera_1); gdImageDestroy (camera_2); log_write ("Loop %d finished.", loop_ctr); loop_ctr++; } return 0; }
// ----- Defines ----- #define USBPortSwapDelay_ms 1000 // ----- Variables ----- uint32_t last_ms; uint8_t attempt; // USB swap pin const GPIO_Pin usb_swap_pin = gpio(A,4); // Esc key strobe const GPIO_Pin strobe_pin = gpio(B,2); const GPIO_Pin sense_pin = gpio(D,5); // ----- Functions ----- // Called early-on during ResetHandler void Device_reset() { } // Called during bootloader initialization
#include <Lib/gpio.h> // Local Includes #include "../weak.h" #include "../device.h" #include "../debug.h" #include "../dfu.desc.h" // ----- Defines ----- // ----- Variables ----- // Debug LED const GPIO_Pin debug_led = gpio(A,19); uint32_t Chip_secure1; uint32_t Chip_secure2; // ----- Functions ----- // Called early-on during ResetHandler void Chip_reset() { // Generating Secure Key print( "Generating Secure Key..." NL ); // Read current 64 bit secure number
/* Basic Control translated from Basic Control */ int main(){ std::shared_ptr<GPIO> gpio(new GPIO(0x40)); //gpio*, clock, data, greentoRed LED_Bar_GPIO ledBar (gpio, 8, 10, false); std::cout << "begin:" << std::endl; ledBar.begin(); for (int i = 0; i <= 20; ++i) { std::cout << "setLevel: "<< i*0.5 << std::endl; ledBar.setLevel(i*0.5); std::this_thread::sleep_for(std::chrono::milliseconds(200)); } // Turn on all LEDs std::cout << "All LEDs on" << std::endl; ledBar.setBits(0x3ff); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn off all LEDs std::cout << "All LEDs off" << std::endl; ledBar.setBits(0x0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LED 1 std::cout << "LED 1 on" << std::endl; // 0b000000000000001 can also be written as 0x1: ledBar.setBits(0b000000000000001); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LEDs 1 and 3 std::cout << "LED 1 + 3 on" << std::endl; // 0b000000000000101 can also be written as 0x5: ledBar.setBits(0b000000000000101); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LEDs 1, 3, 5, 7, 9 std::cout << "LED 1, 3, 5, 7 + 9 on" << std::endl; ledBar.setBits(0x155); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LEDs 2, 4, 6, 8, 10 std::cout << "LED 2, 4, 6, 8 + 10 on" << std::endl; ledBar.setBits(0x2AA); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LEDs 1, 2, 3, 4, 5 std::cout << "LED 1, 2, 3, 4 + 5 on" << std::endl; // 0b000000000011111 == 0x1F ledBar.setBits(0b000000000011111); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Turn on LEDs 6, 7, 8, 9, 10 std::cout << "LED 6, 7, 8, 9 + 10 on" << std::endl; // 0b000001111100000 == 0x3E0 ledBar.setBits(0b000001111100000); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::cout << "Finished LED Test" << std::endl; return EXIT_SUCCESS; }
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb, void *arg) { if (gpio_init(pin, mode) != 0) { return -1; } /* store the callback information for later: */ isr_ctx[_port_num(pin)][_pin_num(pin)].cb = cb; isr_ctx[_port_num(pin)][_pin_num(pin)].arg = arg; /* enable power-up interrupts for this GPIO port: */ SYS_CTRL->IWE |= (1 << _port_num(pin)); /* configure the active flank(s) */ gpio(pin)->IS &= ~_pin_mask(pin); switch(flank) { case GPIO_FALLING: gpio(pin)->IBE &= ~_pin_mask(pin); gpio(pin)->IEV &= ~_pin_mask(pin); gpio(pin)->P_EDGE_CTRL |= (1 << _pp_num(pin)); break; case GPIO_RISING: gpio(pin)->IBE &= ~_pin_mask(pin); gpio(pin)->IEV |= _pin_mask(pin); gpio(pin)->P_EDGE_CTRL &= ~(1 << _pp_num(pin)); break; case GPIO_BOTH: gpio(pin)->IBE |= _pin_mask(pin); break; default: return -1; } /* reset interrupt status */ gpio(pin)->IC = _pin_mask(pin); gpio(pin)->PI_IEN |= (1 << _pp_num(pin)); /* enable global interrupt for the selected GPIO port */ NVIC_EnableIRQ(GPIO_PORT_A_IRQn + _port_num(pin)); /* unmask pin interrupt */ gpio(pin)->IE |= _pin_mask(pin); return 0; }
void gpio_irq_enable(gpio_t pin) { gpio(pin)->IE |= _pin_mask(pin); }
int main(int argc, char *argv[]) { bool hasTouchScreen = QFile::exists("/sys/devices/platform/rpi_ft5406"); // Unless we have a touch screen, wait for keyboard to appear before displaying anything if (!hasTouchScreen) KeyDetection::waitForKeyboard(); int rev = readBoardRevision(); qDebug() << "Board revision is " << rev; int gpioChannel; if (rev == 2 || rev == 3) gpioChannel = 0; else gpioChannel = 2; QApplication a(argc, argv); RightButtonFilter rbf; LongPressHandler lph; GpioInput gpio(gpioChannel); bool runinstaller = false; bool gpio_trigger = false; bool keyboard_trigger = true; bool force_trigger = false; QString defaultLang = "en"; QString defaultKeyboard = "gb"; QString defaultDisplay = "0"; QString defaultPartition = "800"; // Process command-line arguments for (int i=1; i<argc; i++) { // Flag to indicate first boot if (strcmp(argv[i], "-runinstaller") == 0) runinstaller = true; // Enables use of GPIO 3 to force NOOBS to launch by pulling low else if (strcmp(argv[i], "-gpiotriggerenable") == 0) gpio_trigger = true; // Disables use of keyboard to trigger recovery GUI else if (strcmp(argv[i], "-keyboardtriggerdisable") == 0) keyboard_trigger = false; // Forces display of recovery GUI every time else if (strcmp(argv[i], "-forcetrigger") == 0) force_trigger = true; // Allow default language to be specified in commandline else if (strcmp(argv[i], "-lang") == 0) { if (argc > i+1) defaultLang = argv[i+1]; } // Allow default keyboard layout to be specified in commandline else if (strcmp(argv[i], "-kbdlayout") == 0) { if (argc > i+1) defaultKeyboard = argv[i+1]; } // Allow default display mode to be specified in commandline else if (strcmp(argv[i], "-dispmode") == 0) { if (argc > i+1) defaultDisplay = --argv[i+1]; } // Allow default boot partition to be specified in commandline else if (strcmp(argv[i], "-partition") == 0) { if (argc > i+1) defaultPartition = argv[i+1]; } } // Intercept right mouse clicks sent to the title bar a.installEventFilter(&rbf); // Treat long holds as double-clicks if (hasTouchScreen) a.installEventFilter(&lph); #ifdef Q_WS_QWS QWSServer::setCursorVisible(false); #endif QDir settingsdir; settingsdir.mkdir("/settings"); // Set wallpaper and icon, if we have resource files for that if (QFile::exists(":/icons/raspberry_icon.png")) a.setWindowIcon(QIcon(":/icons/raspberry_icon.png")); #ifdef Q_WS_QWS QWSServer::setBackground(BACKGROUND_COLOR); #endif QSplashScreen *splash = new QSplashScreen(QPixmap(":/wallpaper.png")); splash->show(); QApplication::processEvents(); // Wait for drive device to show up QString drive; bool driveReady = false; QTime t; t.start(); while (t.elapsed() < 10000) { if (drive.isEmpty()) { /* We do not know the exact drive name to wait for */ drive = findRecoveryDrive(); if (!drive.isEmpty()) { driveReady = true; break; } } else if (drive.startsWith("/dev")) { if (QFile::exists(drive)) { driveReady = true; break; } } QApplication::processEvents(QEventLoop::WaitForMoreEvents, 100); } if (!driveReady) { QMessageBox::critical(NULL, "Files not found", QString("Cannot find the drive with NOOBS files %1").arg(drive), QMessageBox::Close); return 1; } qDebug() << "NOOBS drive:" << drive; // If -runinstaller is not specified, only continue if SHIFT is pressed, GPIO is triggered, // or no OS is installed (/settings/installed_os.json does not exist) bool bailout = !runinstaller && !force_trigger && !(gpio_trigger && (gpio.value() == 0 )) && hasInstalledOS(drive); if (bailout && keyboard_trigger) { t.start(); while (t.elapsed() < 2000) { QApplication::processEvents(QEventLoop::WaitForMoreEvents, 10); if (QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { bailout = false; qDebug() << "Shift detected"; break; } if (hasTouchScreen && QApplication::mouseButtons().testFlag(Qt::LeftButton)) { bailout = false; qDebug() << "Tap detected"; break; } } } if (bailout) { splash->hide(); showBootMenu(drive, defaultPartition, true); } #ifdef Q_WS_QWS QWSServer::setCursorVisible(true); #endif // Main window in the middle of screen MainWindow mw(drive, defaultDisplay, splash); mw.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, mw.size(), a.desktop()->availableGeometry())); mw.show(); #ifdef ENABLE_LANGUAGE_CHOOSER // Language chooser at the bottom center LanguageDialog* ld = new LanguageDialog(defaultLang, defaultKeyboard); ld->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignHCenter | Qt::AlignBottom, ld->size(), a.desktop()->availableGeometry())); ld->show(); #endif a.exec(); showBootMenu(drive, defaultPartition, false); return 0; }