Пример #1
0
int main(int argc, char *argv[])
{
    int err = 0;
    int len;
    int var;
    int i;
    char *name;
    char *value;
    struct gpio *gpio;
    
    /*
    * display all
    */
    if (1==argc) {
        for (i=0; i<COUNT; i++) {
            gpio = &GPIO[i];

            if (GPIO_R & gpio->flag) {
                var = gpio_read(gpio);
                if (var<0) {
                    continue;
                }
                
                println("%s=%d", gpio->name, var);
            }
        }

        return 0;
    }
    else if (2==argc) {
        char *name = argv[1];
        /*
        * help
        */
        if (0==strcmp("-h", name) || 0==strcmp("--help", name)) {
            usage(argc, argv);
            
            return 0;
        }
        /*
        * get by name
        */
        else if (NULL==strchr(name, '=')) {
            gpio = getgpio_byname(name);
            if (NULL==gpio) {
                println("argv[1](%s) bad name", name);

                return -1;
            }
            
            var = gpio_read(gpio);
            if (var<0) {
                return -1;
            }

            println("%d", var);

            return 0;
        }
    }
    
    /*
    * set by name
    */
    for (i=1; i<argc; i++) {
        char line[1+GPIO_LINE_LEN] = {0};
        len = strlen(argv[i]);
        
        /*
        * check input length
        */
        if (len > GPIO_LINE_LEN) {
            println("argv[%d](%s) too long", i, argv[i]);

            return -1;
        }
        
        strcpy(line, argv[i]);

        /*
        * get name
        */
        name = line;
        value = strchr(line, '=');
        if (NULL==value) {
            println("argv[%d](%s) should as xxx=xxxx", i, argv[i]);

            return -1;
        }
        *value = 0; value++;
        
        /*
        * check name
        */
        gpio = getgpio_byname(name);
        if (NULL==gpio) {
            println("argv[%d](%s) bad name(%s)", i, argv[i], name);
            
            return -1;
        }
        
        /*
        * set value
        */
        err = gpio_write(gpio, atoi(value));
        if (err<0) {
            return err;
        }
    }
    
    return 0;
}
Пример #2
0
void jshPinSetValue(Pin pin, bool value) {
  gpio_dir(&mbedPins[pin], PIN_OUTPUT);
  gpio_write(&mbedPins[pin], value);
}
Пример #3
0
void ble_device_on_connect(void)
{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  gpio_setup(2, GPIO_OUTPUT);
  gpio_write(2, 0);
}
Пример #4
0
static inline void
gpio_clear(struct gpio_opb_softc *sc, bus_size_t o, uint32_t v)
{
	gpio_write(sc, o, gpio_read(sc, o) & ~v);
}
Пример #5
0
int do_led(int which, int mode)
{
//				    WLAN  DIAG  WHITE AMBER DMZ   AOSS  BRIDG MYST/USB 5G
//				    ----- ----- ----- ----- ----- ----- ----- -----    -- 
	static int wrt54g[]	= { 255,  1,    2,    3,    7,    255,  255,  255,    255};
	static int wrtsl[]	= { 255,  1,    5,    7,    0,    255,  255,  255,    255};
	static int whrg54[]	= { 2,    7,    255,  255,  255,  6,    1,    3	 ,    255};
	static int wbr2g54[]	= { 255,  -1,   255,  255,  255,  -6,   255,  255,    255};
	static int wzrg54[]	= { 2,    7,    255,  255,  255,  6,    255,  255,    255};
	static int wr850g1[]	= { 7,    3,    255,  255,  255,  255,  255,  255,    255};
	static int wr850g2[]	= { 0,    1,    255,  255,  255,  255,  255,  255,    255};
	static int wtr54gs[]	= { 1,    -1,   255,  255,  255,  255,  255,  255,    255};
	static int dir320[]	= { -99,   1,     4,    3,  255,  255,  255,   -5,    255};
	static int h618b[]	= { 255,  -1,   255,  255,  255,   -5,   -3,   -4,    255};
	static int wl1600gl[]	= { 1,    -5, 	  0,  255,  255,  2,    255,  255,    255};
	static int wrt310nv1[]	= { 255,   1,     9,    3,  255,  255,  255,  255,    255};
	static int wrt160nv1[]	= { 255,   1,     5,    3,  255,  255,  255,  255,    255};
#ifdef CONFIG_BCMWL5
	static int wnr3500[]	= { 255, 255,     2,  255,  255,   -1,  255,  255,    255};
	static int wnr2000v2[]	= { 255, 255,   255,  255,  255,   -7,  255,  255,    255};
	static int f7d[]	= { 255, 255,   255,  255,   12,   13,  255,   14,    255};
	static int wrt160nv3[]	= { 255,   1,     4,    2,  255,  255,  255,  255,    255};
	static int e900[]	= { 255,  -6,     8,  255,  255,  255,  255,  255,    255};
	static int e1000v2[]	= { 255,  -6,     8,    7,  255,  255,  255,  255,    255};
	static int e3200[]	= { 255,  -3,   255,  255,  255,  255,  255,  255,    255};
	static int wrt320n[]	= { 255,   2,     3,    4,  255,  255,  255,  255,    255};
	static int wrt610nv2[]	= { 255,   5,     3,    0,  255,  255,  255,   -7,    255};
	static int e4200[]		= { 255,   5,    -3,  255,  255,  255,  255,  255,    255};
	static int rtn10u[]		= { 255, 255,   255,  255,  255,   -7,  255,   -8,    255};
	static int rtn10p[]		= { 255,  -6,   255,  255,  255,   -7,  255,  255,    255};
	static int rtn12b1[]	= {  -5, 255,   255,  255,  255,  255,  255,  225,    255};
	static int rtn15u[]		= {   1, 255,     3,  255,  255,  255,  255,   -9,    255};
	static int rtn53[]		= {   0, -17,   255,  255,  255,  255,  255,  255,    255};
	static int rtn66u[]		= { 255, -12,   255,  255,  255,  255,  255,   15,     13};
	static int w1800r[] 	= { 255, -13,   255,  255,  255,  255,  255,  -12,     -5};
	static int l600n[]  	= { 255, 255,   255,  255,  255,  -7,   255,  -8,      -5};
	static int dir620c1[]   = { -6,   -8,   255,  255,  255,  -7,   255,  255,     -5};
	static int wndr3700v3[] = { 255, 255,     2,  255,  255,  -1,   255,  255,    255};
	static int d1800h[]     = { -12, -13,     8,  255,  255,  -10,  255,    15, 255,   11};
	static int tdn6[]       = { 255,  -6,     8,  255,  255,  255,  255,   255, 255,  255};

#endif

	char s[16];
	int n;
	int b = 255, c = 255;
	int ret = 255;

	if ((which < 0) || (which >= LED_COUNT)) return ret;

	switch (nvram_match("led_override", "1") ? MODEL_UNKNOWN : get_model()) {
	case MODEL_WRT54G:
		if (check_hw_type() == HW_BCM4702) {
			// G v1.x
			if ((which != LED_DIAG) && (which != LED_DMZ)) return ret;
			b = (which == LED_DMZ) ? 1 : 4;
			if (mode != LED_PROBE) {
				if (f_read_string("/proc/sys/diag", s, sizeof(s)) > 0) {
					n = atoi(s);
					sprintf(s, "%u", mode ? (n | b) : (n & ~b));
					f_write_string("/proc/sys/diag", s, 0, 0);
				}
			}
			return b;
		}
		switch (which) {
		case LED_AMBER:
		case LED_WHITE:
			if (!supports(SUP_WHAM_LED)) return ret;
			break;
		}
		b = wrt54g[which];
		break;
	case MODEL_WTR54GS:
		b = wtr54gs[which];
		break;
	case MODEL_WRTSL54GS:
		b = wrtsl[which];
		break;
	case MODEL_WHRG54S:
	case MODEL_WHRHPG54:
	case MODEL_WHRG125:
		b = whrg54[which];
		break;
	case MODEL_WZRG54:
	case MODEL_WZRHPG54:
	case MODEL_WZRRSG54:
	case MODEL_WZRRSG54HP:
	case MODEL_WVRG54NF:
	case MODEL_WHR2A54G54:
	case MODEL_WHR3AG54:
	case MODEL_WZRG108:
		b = wzrg54[which];
		break;
/*		
	case MODEL_WHR2A54G54:
		if (which != LED_DIAG) return ret;
		b = 7;
		break;
*/
	case MODEL_WBRG54:
		if (which != LED_DIAG) return ret;
		b = 7;
		break;
	case MODEL_WBR2G54:
		b = wbr2g54[which];
		break;
	case MODEL_WR850GV1:
		b = wr850g1[which];
		break;
	case MODEL_WR850GV2:
	case MODEL_WR100:
		b = wr850g2[which];
		break;
	case MODEL_WL500GP:
		if (which != LED_DIAG) return ret;
		b = -1;	// power light
		break;
	case MODEL_WL500W:
		if (which != LED_DIAG) return ret;
		b = -5;	// power light
		break;
	case MODEL_DIR320:
		b = dir320[which];
		break;
	case MODEL_H618B:
		b = h618b[which];
		break;
	case MODEL_WL1600GL:
		b = wl1600gl[which];
		break;
	case MODEL_WL500GPv2:
	case MODEL_WL500GD:
	case MODEL_WL520GU:
	case MODEL_WL330GE:
		if (which != LED_DIAG) return ret;
		b = -99;	// Invert power light as diag indicator
		break;
#ifdef CONFIG_BCMWL5
	case MODEL_RTN12:
		if (which != LED_DIAG) return ret;
		b = -2;	// power light
		break;
	case MODEL_RTN10:
	case MODEL_RTN16:
		if (which != LED_DIAG) return ret;
		b = -1;	// power light
		break;
	case MODEL_RTN15U:
		b = rtn15u[which];
		break;
	case MODEL_RTN53:
	case MODEL_RTN53A1:
		b = rtn53[which];
		break;
	case MODEL_RTN66U:
		b = rtn66u[which];
		break;
	case MODEL_W1800R:
		b = w1800r[which];
		break;
	case MODEL_D1800H:
		if (which == LED_DIAG) {
			// power led gpio: 0x02 - white, 0x13 - red 
			b = (mode) ? 13 : 2;
			c = (mode) ? 2 : 13;
		} else
			b = d1800h[which];
		break;
	case MODEL_WNDR3700v3:
		b = wndr3700v3[which];
		break;
	case MODEL_WNR3500L:
	case MODEL_WNR3500LV2:
		if (which == LED_DIAG) {
			// power led gpio: 0x03 - green, 0x07 - amber
			b = (mode) ? 7 : 3;
			c = (mode) ? 3 : 7;
		} else
			b = wnr3500[which];
		break;
	case MODEL_WNR2000v2:
		if (which == LED_DIAG) {
			// power led gpio: 0x01 - green, 0x02 - amber
			b = (mode) ? 2 : 1;
			c = (mode) ? 1 : 2;
		} else
			b = wnr2000v2[which];
		break;
	case MODEL_F7D3301:
	case MODEL_F7D3302:
	case MODEL_F7D4301:
	case MODEL_F7D4302:
	case MODEL_F5D8235v3:
		if (which == LED_DIAG) {
			// power led gpio: 10 - green, 11 - red
			b = (mode) ? 11 : -10;
			c = (mode) ? -10 : 11;
		} else
			b = f7d[which];
		break;
	case MODEL_E1000v2:
		b = e1000v2[which];
		break;
	case MODEL_E900:
	case MODEL_E1500:
	case MODEL_E1550:
	case MODEL_E2500:
		b = e900[which];
		break;
	case MODEL_E3200:
		b = e3200[which];
		break;
	case MODEL_WRT160Nv3:
		b = wrt160nv3[which];
		break;
	case MODEL_WRT320N:
		b = wrt320n[which];
		break;
	case MODEL_WRT610Nv2:
		b = wrt610nv2[which];
		break;
	case MODEL_E4200:
		b = e4200[which];
		break;
	case MODEL_RTN10U:
		b = rtn10u[which];
		break;
	case MODEL_RTN10P:
		b = rtn10p[which];
		break;
	case MODEL_RTN12B1:
		b = rtn12b1[which];
		break;
	case MODEL_L600N:
		b = l600n[which];
		break;
	case MODEL_DIR620C1:
		b = dir620c1[which];
	case MODEL_TDN60: //bwq518
	case MODEL_TDN6:
		b = tdn6[which];
		break;
#endif
/*
	case MODEL_RT390W:
		break;
*/
	case MODEL_MN700:
		if (which != LED_DIAG) return ret;
		b = 6;
		break;
	case MODEL_WLA2G54L:
		if (which != LED_DIAG) return ret;
		b = 1;
		break;
	case MODEL_WRT300N:
		if (which != LED_DIAG) return ret;
		b = 1;
		break;
	case MODEL_WRT310Nv1:
		b = wrt310nv1[which];
		break;
	case MODEL_WRT160Nv1:
		b = wrt160nv1[which];
		break;
	default:
		sprintf(s, "led_%s", led_names[which]);
		if (nvget_gpio(s, &b, &n)) {
			if ((mode != LED_PROBE) && (n)) mode = !mode;
			ret = (n) ? b : ((b) ? -b : -99);
			goto SET;
		}
		return ret;
	}

	ret = b;
	if (b < 0) {
		if (b == -99) b = 0; // -0 substitute
			else b = -b;
	}
	else if (mode != LED_PROBE) {
		mode = !mode;
	}

SET:
	if (b < 16) {
		if (mode != LED_PROBE) {
			gpio_write(1 << b, mode);

			if (c < 0) {
				if (c == -99) c = 0;
				else c = -c;
			}
			else mode = !mode;
			if (c < 16) gpio_write(1 << c, mode);
		}
	}

	return ret;
}
Пример #6
0
int main (void)
{
	
	//UIO driver

	uiofd = open("/dev/uio0", O_RDWR);
	if (uiofd < 1)
	{
		fprintf(stderr, "Invalid UIO device file.\n");
		return -1;
	}

	uioptr = mmap(NULL, GPIO_MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, uiofd, 0);	
	if (uioptr == MAP_FAILED)
		{
		printf("mmap call failure.\n");
		exit(-1);
		}	

	// set buttons as inputs
	gpio_write(uioptr, GPIO_TRI_OFFSET, 0x1F);	

	// enable interrupts
	gpio_write(uioptr, GPIO_GLOBAL_IRQ, 0x80000000);
	gpio_write(uioptr, GPIO_IRQ_CONTROL, 0x1);
	
	// Ensure IRQ status is initially 0
	if (gpio_read(uioptr, GPIO_IRQ_STATUS))
	{
		gpio_write(uioptr, GPIO_IRQ_STATUS, 0x1); // writing 1 to this address toggles IRQ status between 0 and 1
	}

	// MAIN LOOP
	char c;
	int i;
	while(1){
		// Loop through the alphabet unless interrupted
		for (c = 'A'; c <= 'Z'; c++) {
			fprintf(stdout, "%c\n", c);
			for (i=0;i<=DELAY; i++);
		
			// INTERRUPT HANDLING (blocking read)
	
			/*int pending = 0;
			int reenable = 1;
			read(uiofd, (void *)&pending, sizeof(int));
			interrupt_service_routine(uioptr);
			clear_interrupt();
			write(uiofd, (void *)&reenable, sizeof(int)); */// reenable buttons 

			// INTERRUPT HANDLING (polling with select)
			int pending = 0;
			int reenable = 1;
			struct timeval tv;
			tv.tv_sec = 0.3;
			int return_val = 0;
			fd_set set;	// A set of file descriptors to pass to select 
			FD_ZERO(&set);	// Initialize the set
			FD_SET(uiofd,&set);	// Add uiofd to the set

			// select waits until uiofd is read ready or until timeout (tv.tvsec)
			// returns 1 if a read of uiofd would NOT block; otherwise returns 0 (timeout) 
			return_val = select(uiofd+1, &set, NULL, NULL, &tv);

			if (return_val == -1)
			{
				perror("select()\n");
			}
			else if (return_val)
			{
				// uiofd read ready (no timeout)
				interrupt_service_routine(uioptr);	// run the ISR
				clear_interrupt();			// acknowledge and reset interrupt status bit
				write(uiofd, (void *)&reenable, sizeof(int)); // reenable buttons
				read(uiofd, (void *)&pending, sizeof(int)); //read to return the uiofd file descriptor to blocking status (until another interrupt)
			}
		}
	}

	// Unmap the UIO device (never reached on normal execution)
	munmap(uioptr, GPIO_MAP_SIZE);
	return 0;
}
Пример #7
0
/*
 * Internal - Write one bit
 */
static void
lcd_wr_bit(int b) {
	gpio_write(lcd_sdin,b);
	gpio_write(lcd_sclk,1);
	gpio_write(lcd_sclk,0);
}
Пример #8
0
//-------------------------------------------------------
void LEDR(bool status){
	if (status == true)	gpio_write(17,0);
	else			gpio_write(17,1);
}
Пример #9
0
static void leds_on(int core)
{
  gpio_write(core, led_data);  
}
Пример #10
0
static void leds_off(int core)
{
  gpio_write(core, 0);  
}
Пример #11
0
void ble_device_on_connect(void)
{
	gpio_write(SWITCH_LED, 0);
}
Пример #12
0
void ble_device_on_disconnect(uint8_t reason)
{
	ble_device_set_advertising_interval(250);
  ble_device_start_advertising();
	gpio_write(SWITCH_LED, 1);
}
Пример #13
0
void hw_sync_enable(const hw_sync_mode_t hw_sync_mode){
    gpio_write(&gpio_hw_sync_enable, hw_sync_mode==1);
}
Пример #14
0
void my_characteristic_write_callback(ble_characteristic_info_t* char_info, uint16_t offset, uint16_t len, uint8_t* data) 
{   
    
    // Write to sensor ID characteristic value?
	  if ((char_info == &characteristic_sensorID_info) && (offset == 0) && (len == sizeof(sensor_bridge.sensorID))) 
    {
			  // Copy new data to local buffer, and store it to persistent memory.
        memcpy((uint8_t*)&sensor_bridge.sensorID, data, len); 
        pstorage_driver_request_store((uint8_t*)(&sensor_bridge.sensorID));
    }
		
		// Write to beacon frequency characteristic value?
    if ((char_info == &characteristic_sensorBeaconFrequency_info) && (offset == 0) && (len == sizeof(sensor_bridge.beaconFrequency))) 
    {
        beaconFrequency_t tmp_beaconFrequency;
        memcpy((uint8_t*)&tmp_beaconFrequency, data, len);    
        
			  // Check if new value is valid.
        if((tmp_beaconFrequency >= 20) && (tmp_beaconFrequency <= 10240))
        {
					  // Copy new data to local buffer, and store it to persistent memory.
            sensor_bridge.beaconFrequency = tmp_beaconFrequency;
            pstorage_driver_request_store((uint8_t*)(&sensor_bridge.beaconFrequency));
        }
    }
    
		// Write to led state characteristic value?
    if ((char_info == &characteristic_sensorLedState_info) && (offset == 0) && (len == sizeof(sensor_bridge.led_state))) 
    {
			  // Copy new data to local buffer, and update state of LED diode.
        memcpy((uint8_t*)&sensor_bridge.led_state, data, len);  
			  led_control_update_char(sensor_bridge.led_state, LED_TIMEOUT_CHAR_MS);
    }
    
		// Write to config characteristic value?
    if ((char_info == &characteristic_sensorConfig_info) && (offset == 0) && (len == sizeof(sensor_bridge.config))) 
    {
        uint32_t baud_rate_reg;
			
			  // Copy new data to local buffer, and store it to persistent memory.
        memcpy((uint8_t*)&sensor_bridge.config, data, len); 
        pstorage_driver_request_store((uint8_t*)(&sensor_bridge.config));
        if(bridge_set_baud_rate_register(sensor_bridge.config.baud_rate, &baud_rate_reg) == true)
        {
            NRF_UART0->BAUDRATE = (baud_rate_reg << UART_BAUDRATE_BAUDRATE_Pos);  
        }
    } 
    
		// Write to data down characteristic value?
    if ((char_info == &characteristic_sensorData_down_info) && (offset == 0) && (len <= sizeof(sensor_bridge.data_down))) 
    {
        memcpy((uint8_t*)&sensor_bridge.data_down, data, len);
        //bridge_rcv_from_ble_mark = true;
        
			  // Update relay state.
			  if (sensor_bridge.data_down.payload[0] == 0) 
				{
					  gpio_write(RELAY_PIN, false);
				}
				else if (sensor_bridge.data_down.payload[0] == 1) 
				{
						gpio_write(RELAY_PIN, true);
				}
    }
    
		// Write to sensor passkey characteristic value?
    if ((char_info == &characteristic_sensorPasskey_info) && (offset == 0) && (len == 6)) 
    {
			  // Copy new data to local buffer, and store it to persistent memory.
        memcpy((uint8_t*)&sensor_bridge.passkey, data, len);  
        pstorage_driver_request_store((uint8_t*)(&sensor_bridge.passkey));
			
			  // Set flag to clear bond manager.
        ble_clear_bondmngr_request();
    }
    
		// Write to working encryption mode characteristic value?
    if ((char_info == &characteristic_sensorMitmReqFlag_info) && (offset == 0) && (len == sizeof(sensor_bridge.mitm_req_flag)))
    {
			  // Copy new data to local buffer, and store it to persistent memory.
        sensor_bridge.mitm_req_flag = (data[0] == 1);
        pstorage_driver_request_store((uint8_t*)(&sensor_bridge.mitm_req_flag));
    }
}
Пример #15
0
void
pin_write(enum swd_pin pin, int val)
{
        gpio_write(pin, val);
}
Пример #16
0
int main(void) 
{
    gpio_set_pin_digital_input(BUTTON_PIN, PIN_PULL_UP);                                           // Set button pin to be input, with pull up.
    while(gpio_read(BUTTON_PIN) == 0);                                                             // If button pin is pressed, wait to be released.
    nrf_delay_us(50000);

	  // Initialize some global variables.
    if (!comfort_init()) 
    {
        blink(101); 
    }
    
		// Initialize BLE server modules.
    if (!ble_init_server(&server_def, pstorage_driver_init, &sensor_bridge.mitm_req_flag))
    { 
        blink(101); 
    }
    
		// Initialize uart module.
		if (!bridge_uart_init())
    { 
        blink(101); 
    }
    
		/* NOTE: First release: We are going to use a simple RELAY output in this module, the UART app will be upgraded over the air when 
											      the backend is ready to support this functionality.
		*/
		
		NRF_UART0->PSELTXD = 0xFFFFFFFF;
		gpio_write(RELAY_PIN, false);	
		gpio_set_pin_digital_output(RELAY_PIN, PIN_DRIVE_S0S1);
		
		// Initialize services and characteristics for non-onboarding mode.
    if(onboard_get_mode() == ONBOARD_MODE_IDLE)
    {
			  // Check whether there is a need for MITM encryption.
        uint16_t read_enc_flag  = (sensor_bridge.mitm_req_flag ? BLE_CHARACTERISTIC_READ_ENC_REQUIRE  : BLE_CHARACTERISTIC_READ_ENC_REQUIRE_NO_MITM);
        uint16_t write_enc_flag = (sensor_bridge.mitm_req_flag ? BLE_CHARACTERISTIC_WRITE_ENC_REQUIRE : BLE_CHARACTERISTIC_WRITE_ENC_REQUIRE_NO_MITM);
        
        short_service_uuid = sensor_bridge.mitm_req_flag ? short_service_relayr_uuid : short_service_relayr_open_comm_uuid;         
      
			  // Adding user service.
        if (!ble_add_service(short_service_uuid, 0, 0, &service_info)) 
        {
            blink(103);
        }
      
				// Adding related characteristics.
				
        if (!ble_add_characteristic(&service_info,
																		characteristic_sensorID_uuid,
																		BLE_CHARACTERISTIC_CAN_READ | read_enc_flag,
																		(const uint8_t*)"SensorID", 
																		(const uint8_t*)sensor_bridge.sensorID,
																		sizeof(sensorID_t),
																		&characteristic_sensorID_info))
        {
            blink(104);
        }
      
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorBeaconFrequency_uuid,
                                    BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_WRITE | read_enc_flag | write_enc_flag,
                                    (const uint8_t*)"SensorBeaconFrequency", 
                                    (const uint8_t*)&sensor_bridge.beaconFrequency,
                                    sizeof(sensor_bridge.beaconFrequency),
                                    &characteristic_sensorBeaconFrequency_info)) 
        {
            blink(104);
        }
        
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorLedState_uuid,
                                    BLE_CHARACTERISTIC_CAN_WRITE | write_enc_flag,
                                    (const uint8_t*)"SensorLedState", 
                                    (const uint8_t*)&sensor_bridge.led_state,
                                    sizeof(sensor_bridge.led_state),
                                    &characteristic_sensorLedState_info)) 
        {
            blink(104);
        }
        
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorConfig_uuid,
                                    BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_WRITE | read_enc_flag | write_enc_flag,
                                    (const uint8_t*)"SensorConfig", 
                                    (const uint8_t*)&sensor_bridge.config,
                                    sizeof(sensor_bridge.config),
                                    &characteristic_sensorConfig_info)) 
        {
            blink(104);
        }
        
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorData_up_uuid,
                                    BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_NOTIFY | BLE_CHARACTERISTIC_CAN_INDICATE | read_enc_flag,
                                    (const uint8_t*)"SensorDataUp", 
                                    (const uint8_t*)&sensor_bridge.data_up,
                                    sizeof(sensor_bridge.data_up),
                                    &characteristic_sensorData_up_info)) 
        {
            blink(104);
        }
        
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorData_down_uuid,
                                    BLE_CHARACTERISTIC_CAN_WRITE | write_enc_flag,
                                    (const uint8_t*)"SensorDataDown", 
                                    (const uint8_t*)&sensor_bridge.data_down,
                                    sizeof(sensor_bridge.data_down),
                                    &characteristic_sensorData_down_info)) 
        {
            blink(104);
        }
    }
		// Initialize services and characteristics for onboarding mode.
    else
    {
			  // Adding user service.
        if (!ble_add_service(short_service_config_uuid, 0, 0, &service_info)) 
        {
            blink(103);
        }
        
				// Adding related characteristics.
				
        if (!ble_add_characteristic(&service_info,
																		characteristic_sensorID_uuid,
																		BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_WRITE,
																		(const uint8_t*)"SensorID", 
																		(const uint8_t*)sensor_bridge.sensorID,
																		sizeof(sensorID_t),
																		&characteristic_sensorID_info)) 
        {
            blink(104);
        }
      
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorPasskey_uuid,
                                    BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_WRITE,
                                    (const uint8_t*)"SensorPasskey", 
                                    (const uint8_t*)sensor_bridge.passkey,
                                    6,
                                    &characteristic_sensorPasskey_info))
        {
            blink(104);
        }
        
        if (!ble_add_characteristic(&service_info,
                                    characteristic_sensorMitmReqFlag_uuid,
                                    BLE_CHARACTERISTIC_CAN_READ | BLE_CHARACTERISTIC_CAN_WRITE,
                                    (const uint8_t*)"SensorMitmRequireFlag", 
                                    (const uint8_t*)&sensor_bridge.mitm_req_flag,
                                    sizeof(security_level_t),
                                    &characteristic_sensorMitmReqFlag_info)) 
        {
            blink(104);
        }
    }
    
		// Adding Device Informaiton Service.
    if (!ble_add_device_information_service()) 
    {
        blink(102);
    }
    
		// Adding Battery Service.
    if (!ble_add_bat_service()) 
    {
        blink(102);
    }

		// Starting server.
    if (!ble_start_server()) 
    { 
        blink(105);
    }
    
		// Initializing the advertising functionality.
    if (!ble_init_advertising()) 
    {
        blink(106);
    } 
    
		// Start advertising.
    if (!ble_start_advertising(sensor_bridge.beaconFrequency)) 
    {
        blink(106);
    }
    
    ble_run();

    blink(107);
} 
Пример #17
0
static void gpio_callback_low(GtkWidget *widget, GtkEntry *entry)
{
    int pin_number = atoi(gtk_entry_get_text(entry));
    gpio_config(pin_number, 1);
    gpio_write(pin_number, 0);
}
Пример #18
0
void LEDG(bool status){
        if (status == true)     gpio_write(18,0);
        else                    gpio_write(18,1);
}
Пример #19
0
static int usb_config_gpio_write(struct bladerf *dev, uint32_t val)
{
    return gpio_write(dev, 0, val);
}
Пример #20
0
void adxl362_sample_trigger(bool trigger)
{
	gpio_write(adxl362_s.int_pin_gpio, ADXL362_INT2_PIN, (trigger ? 1 : 0));
}
Пример #21
0
static int usb_expansion_gpio_dir_write(struct bladerf *dev, uint32_t val)
{
    return gpio_write(dev, 44, val);
}
Пример #22
0
//******************************************************************************
static void usurp_pin(PinName pin, int state)
{
    gpio_t gpio;
    gpio_init_out(&gpio, pin);
    gpio_write(&gpio, state);
}
Пример #23
0
void server_task(void *p)
{
    bool camera_ok = false;

    // Power cycle the the camera
    gpio_enable(ARDUCAM_PWR, GPIO_OUTPUT);
    printf("Camera power cycle\n");
    gpio_write(ARDUCAM_PWR, 1);
    delay_ms(250);
    gpio_write(ARDUCAM_PWR, 0);
    delay_ms(250);

    camera_ok = arducam_setup();
    if (!camera_ok) {
        printf("Camera init failed!\n"); 
    }

    while (1) {
        struct sockaddr_in server_addr, client_addr;
        int server_sock, client_sock;
        socklen_t sin_size;
        bzero(&server_addr, sizeof(struct sockaddr_in));
        server_addr.sin_family = AF_INET;
        server_addr.sin_addr.s_addr = INADDR_ANY;
        server_addr.sin_port = htons(80);

        int recbytes;

        do {
            if (-1 == (server_sock = socket(AF_INET, SOCK_STREAM, 0))) {
                printf("Socket error\n");
                break;
            }

            if (-1 == bind(server_sock, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr))) {
                printf("bind fail\n");
                break;
            }

            printf(" bind port: %d\n", ntohs(server_addr.sin_port));

            if (-1 == listen(server_sock, 5)) {
                printf("listen fail\n");
                break;
            }

            sin_size = sizeof(client_addr);

            for (;;) {
                if ((client_sock = accept(server_sock, (struct sockaddr *) &client_addr, &sin_size)) < 0) {
                    printf("accept fail\n");
                    continue;
                }

                printf("Client from %s:%d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));

                int opt = 50;
                if (lwip_setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int)) < 0) {
                    printf("failed to set timeout on socket\n");
                }
                while ((recbytes = read(client_sock, buffer, BUF_SIZE)) > 0) {
                    buffer[recbytes] = 0;
                }

                sprintf(buffer, "HTTP/1.1 200 OK\nContent-Type: image/jpeg; charset=utf-8\nConnection: close\n\n");

                if (write(client_sock, buffer, strlen(buffer)) > 0) {
                    if (camera_ok) {
                        uint32_t retries = 4;
                        bool success;
                        while(retries--) {
                            success = arducam_capture();
                            if (success) {
                                break;
                            } else {
                                printf("Capture retry\n"); 
                                delay_ms(10); // Arbitrary value
                            }
                        }
                        if (success) {
                            printf("Reading fifo\n"); 
                            arudcam_fifo_to_socket(client_sock);
                            printf("---\n");
                        }
                    }
                }

                if (recbytes <= 0) {
                    close(client_sock);
                }
            }
        } while (0);
    }
}
Пример #24
0
void
launcher_init(void)
{
    memset(_loaded, 1, 10);

    _phi            = -1 * (45 / sqrt(pow(FRAME_WIDTH, 2) + pow(FRAME_HEIGHT, 2)));
    _chamber[0]     = gpio_calculate(2, 14);    gpio_init(_chamber[0], 0); gpio_write(_chamber[0], 0);
    _chamber[1]     = gpio_calculate(2, 12);    gpio_init(_chamber[1], 0); gpio_write(_chamber[1], 0);
    _chamber[2]     = gpio_calculate(2, 10);    gpio_init(_chamber[2], 0); gpio_write(_chamber[2], 0);
    _chamber[3]     = gpio_calculate(2, 8);     gpio_init(_chamber[3], 0); gpio_write(_chamber[3], 0);
    _chamber[4]     = gpio_calculate(2, 6);     gpio_init(_chamber[4], 0); gpio_write(_chamber[4], 0);
    _chamber[5]     = gpio_calculate(2, 7);     gpio_init(_chamber[5], 0); gpio_write(_chamber[5], 0);
    _chamber[6]     = gpio_calculate(2, 9);     gpio_init(_chamber[6], 0); gpio_write(_chamber[6], 0);
    _chamber[7]     = gpio_calculate(2, 11);    gpio_init(_chamber[7], 0); gpio_write(_chamber[7], 0);
    _chamber[8]     = gpio_calculate(2, 13);    gpio_init(_chamber[8], 0); gpio_write(_chamber[8], 0);
    _chamber[9]     = gpio_calculate(2, 15);    gpio_init(_chamber[9], 0); gpio_write(_chamber[9], 0);

    _disabled       = gpio_calculate(0, 9);     gpio_init(_disabled, 0);
    _feedback       = gpio_calculate(0, 8);     gpio_init(_feedback, 1);
    _reload_led     = gpio_calculate(2, 5);     gpio_init(_reload_led, 0);
    _reload_switch  = gpio_calculate(0, 2);     gpio_init(_reload_switch, 1);

    gpio_write(_disabled, 1);
    gpio_write(_reload_led, 0);

    control_set_pan(90);
    control_set_tilt(90);

    control_init();
}
Пример #25
0
void t9()
{
   int s, oc, c, e;
   uint32_t p[10];

   printf("Script store/run/status/stop/delete tests.\n");

   gpio_write(GPIO, 0); /* need known state */

   /*
   100 loops per second
   p0 number of loops
   p1 GPIO
   */
   char *script="\
   ldap 0\
   ldva 0\
   label 0\
   w p1 1\
   milli 5\
   w p1 0\
   milli 5\
   dcrv 0\
   ldav 0\
   ldpa 9\
   jp 0";

   callback(GPIO, RISING_EDGE, t9cbf);

   s = store_script(script);
   oc = t9_count;
   p[0] = 99;
   p[1] = GPIO;
   run_script(s, 2, p);
   time_sleep(2);
   c = t9_count - oc;
   CHECK(9, 1, c, 100, 0, "store/run script");

   oc = t9_count;
   p[0] = 200;
   p[1] = GPIO;
   run_script(s, 2, p);
   while (1)
   {
      e = script_status(s, p);
      if (e != PI_SCRIPT_RUNNING) break;
      time_sleep(0.5);
   }
   c = t9_count - oc;
   time_sleep(0.1);
   CHECK(9, 2, c, 201, 0, "run script/script status");

   oc = t9_count;
   p[0] = 2000;
   p[1] = GPIO;
   run_script(s, 2, p);
   while (1)
   {
      e = script_status(s, p);
      if (e != PI_SCRIPT_RUNNING) break;
      if (p[9] < 1900) stop_script(s);
      time_sleep(0.1);
   }
   c = t9_count - oc;
   time_sleep(0.1);
   CHECK(9, 3, c, 110, 10, "run/stop script/script status");

   e = delete_script(s);
   CHECK(9, 4, e, 0, 0, "delete script");
}
Пример #26
0
int main(int argc, char * const argv[])
{
  bitbang_init_st init;
  bitbang_handle_st *hdl = NULL;
  int cs = -1, clk = -1, in = -1, out = -1;
  gpio_st cs_gpio;
  int opt;
  int is_write = 0;
  int is_read = 0;
  int read_bits = 0;
  int write_bits = 0;
  int read_bytes = 0;
  int write_bytes = 0;
  int i;
  uint8_t *read_buf = NULL;;
  uint8_t *write_buf = NULL;;
  bitbang_clk_edge_en dout_edge = BITBANG_CLK_EDGE_FALLING;
  bitbang_clk_edge_en din_edge = BITBANG_CLK_EDGE_RISING;
  bitbang_pin_value_en clk_start = BITBANG_PIN_HIGH;
  bitbang_pin_value_en cs_value = BITBANG_PIN_HIGH;
  spi_context_st ctx;
  bitbang_io_st io;
  int rc = 0;
  int binary = 0;

  memset(&ctx, sizeof(ctx), 0);
  gpio_init_default(&ctx.sc_clk);
  gpio_init_default(&ctx.sc_mosi);
  gpio_init_default(&ctx.sc_miso);
  gpio_init_default(&cs_gpio);

  while ((opt = getopt(argc, argv, "bs:S:c:C:o:O:i:I:w:r:")) != -1) {
    switch (opt) {
    case 'b':
      binary = 1;
      break;
    case 's':
      cs = atoi(optarg);
      break;
    case 'S':
      if (!strcmp(optarg, "high")) {
        cs_value = BITBANG_PIN_HIGH;
      } else if (!strcmp(optarg, "low")) {
        cs_value = BITBANG_PIN_LOW;
      } else {
        usage();
        exit(-1);
      }
      break;
    case 'c':
      clk = atoi(optarg);
      break;
    case 'C':
      if (!strcasecmp(optarg, "high")) {
        clk_start = BITBANG_PIN_HIGH;
      } else if (!strcasecmp(optarg, "low")) {
        clk_start = BITBANG_PIN_LOW;
      } else {
        usage();
        exit(-1);
      }
      break;
    case 'o':
      out = atoi(optarg);
      break;
    case 'O':
      if (!strcasecmp(optarg, "rising")) {
        dout_edge = BITBANG_CLK_EDGE_RISING;
      } else if (!strcasecmp(optarg, "falling")) {
        dout_edge = BITBANG_CLK_EDGE_FALLING;
      } else {
        usage();
        exit(-1);
      }
      break;
    case 'i':
      in = atoi(optarg);
      break;
    case 'I':
      if (!strcasecmp(optarg, "rising")) {
        din_edge = BITBANG_CLK_EDGE_RISING;
      } else if (!strcasecmp(optarg, "falling")) {
        din_edge = BITBANG_CLK_EDGE_FALLING;
      } else {
        usage();
        exit(-1);
      }
      break;
    case 'w':
      is_write = 1;
      write_bits = atoi(optarg);
      if (write_bits <= 0) {
        usage();
        exit(-1);
      }
      break;
    case 'r':
      is_read = 1;
      read_bits = atoi(optarg);
      if (read_bits <= 0) {
        usage();
        exit(-1);
      }
      break;
    default:
      usage();
      exit(-1);
    }
  }

  if (clk < 0 || in < 0 || out < 0) {
    usage();
    exit(-1);
  }

  if ((!is_read && !is_write)) {
    usage();
    exit(-1);
  }

  write_bytes = ((write_bits + 7) / 8);
  if (write_bytes) {
    write_buf = calloc(write_bytes, sizeof(uint8_t));
    if (!write_buf) {
      goto out;
    }
    if (binary) {
      size_t written_bytes;
      written_bytes = fread(write_buf, sizeof(*write_buf), write_bytes, stdin);
      if( written_bytes != write_bytes ) {
        goto out;
      }
    } else {
      for (i = 0; i < write_bytes && i + optind < argc; i++) {
        write_buf[i] = strtoul(argv[i + optind], NULL, 0);
      }
    }
  }

  read_bytes = ((read_bits + 7) / 8);
  if (read_bytes) {
    read_buf = calloc(read_bytes, sizeof(uint8_t));
    if (!read_buf) {
      goto out;
    }
  }

  if (gpio_open(&ctx.sc_clk, clk) || gpio_open(&ctx.sc_miso, in)
      || gpio_open(&ctx.sc_mosi, out)) {
    goto out;
  }

  /* change GPIO directions, only MISO is input, all others are output */
  if (gpio_change_direction(&ctx.sc_clk, GPIO_DIRECTION_OUT)
      || gpio_change_direction(&ctx.sc_miso, GPIO_DIRECTION_IN)
      || gpio_change_direction(&ctx.sc_mosi, GPIO_DIRECTION_OUT)) {
    goto out;
  }

  if (cs != -1) {
    if (gpio_open(&cs_gpio, cs)) {
        goto out;
    }
    if (gpio_change_direction(&cs_gpio, GPIO_DIRECTION_OUT)) {
      goto out;
    }
  }

  bitbang_init_default(&init);
  init.bbi_clk_start = clk_start;
  init.bbi_data_out = dout_edge;
  init.bbi_data_in = din_edge;
  init.bbi_freq = 1000 * 1000;   /* 1M Hz */
  init.bbi_pin_f = spi_pin_f;
  init.bbi_context = &ctx;

  hdl = bitbang_open(&init);
  if (!hdl) {
    goto out;
  }

  if (cs != -1) {
    /* have chip select */
    gpio_write(&cs_gpio, ((cs_value == BITBANG_PIN_HIGH)
                          ? GPIO_VALUE_HIGH : GPIO_VALUE_LOW));
  }

  memset(&io, sizeof(io), 0);
  io.bbio_in_bits = read_bits;
  io.bbio_din = read_buf;
  io.bbio_out_bits = write_bits;
  io.bbio_dout = write_buf;

  rc = bitbang_io(hdl, &io);
  if (rc != 0) {
    goto out;
  }

  if (binary) {
    fwrite(read_buf, sizeof(*read_buf), read_bytes, stdout);
  } else {
    if (write_bits) {
      printf("Wrote %u bits:", write_bits);
      for (i = 0; i < write_bytes; i++) {
        printf(" %02x", write_buf[i]);
      }
      printf("\n");
    }

    if (read_bits) {
      printf("Read %u bits:", read_bits);
      for (i = 0; i < read_bytes; i++) {
        printf(" %02x", read_buf[i]);
      }
      printf("\n");
    }
  }

 out:
  if (hdl) {
    bitbang_close(hdl);
  }
  gpio_close(&ctx.sc_clk);
  gpio_close(&ctx.sc_miso);
  gpio_close(&ctx.sc_mosi);
  if (cs != -1) {
    /* reset have chip select */
    gpio_write(&cs_gpio, ((cs_value == BITBANG_PIN_HIGH)
                          ? GPIO_VALUE_LOW : GPIO_VALUE_HIGH));
    gpio_close(&cs_gpio);
  }

  if (read_buf) {
    free(read_buf);
  }
  if (write_buf) {
    free(write_buf);
  }
  return rc;
}
Пример #27
0
void t9(int pi)
{
   int s, oc, c, e, id;
   uint32_t p[10];

   printf("Script store/run/status/stop/delete tests.\n");

   gpio_write(pi, GPIO, 0); /* need known state */

   /*
   100 loops per second
   p0 number of loops
   p1 GPIO
   */
   char *script="\
   ld p9 p0\
   tag 0\
   w p1 1\
   mils 5\
   w p1 0\
   mils 5\
   dcr p9\
   jp 0";

   id = callback(pi, GPIO, RISING_EDGE, t9cbf);

   s = store_script(pi, script);

   /* Wait for script to finish initing. */
   while (1)
   {
      time_sleep(0.1);
      e = script_status(pi, s, p);
      if (e != PI_SCRIPT_INITING) break;
   }

   oc = t9_count;
   p[0] = 99;
   p[1] = GPIO;
   run_script(pi, s, 2, p);
   time_sleep(2);
   c = t9_count - oc;
   CHECK(9, 1, c, 100, 0, "store/run script");

   oc = t9_count;
   p[0] = 200;
   p[1] = GPIO;
   run_script(pi, s, 2, p);
   while (1)
   {
      time_sleep(0.1);
      e = script_status(pi, s, p);
      if (e != PI_SCRIPT_RUNNING) break;
   }
   c = t9_count - oc;
   time_sleep(0.1);
   CHECK(9, 2, c, 201, 0, "run script/script status");

   oc = t9_count;
   p[0] = 2000;
   p[1] = GPIO;
   run_script(pi, s, 2, p);
   while (1)
   {
      time_sleep(0.1);
      e = script_status(pi, s, p);
      if (e != PI_SCRIPT_RUNNING) break;
      if (p[9] < 1600) stop_script(pi, s);
   }
   c = t9_count - oc;
   time_sleep(0.1);
   CHECK(9, 3, c, 410, 10, "run/stop script/script status");

   e = delete_script(pi, s);
   CHECK(9, 4, e, 0, 0, "delete script");

   callback_cancel(id);
}