コード例 #1
0
// Sends a command to OLED
static void oled_cmd(uint8_t cmd, uint32_t count, uint8_t *data) {
  pin_clear(OLED_NCS);
  pin_clear(OLED_A0);
  SPI_I2S_SendData(OLED_SPI, cmd);
  oled_wait_spi();
  pin_set(OLED_A0);
  if(count) {
    oled_dma(data, count);
    oled_wait_dma();
    oled_wait_spi();
  }
  pin_set(OLED_NCS);
}
コード例 #2
0
void init_segment(void){

    segmentClock = &D[0];
    segmentLatch = &D[1];
    segmentData = &D[2];

    pin_digitalOut(segmentClock);
    pin_digitalOut(segmentLatch);
    pin_digitalOut(segmentData);

    pin_clear(segmentClock);
    pin_clear(segmentLatch);
    pin_clear(segmentData);	
}
コード例 #3
0
ファイル: audio.c プロジェクト: jacobkingery/space_balls
void init_audio(_PIN *request_pin) {
    audio.play = START;
    pin_digitalOut(request_pin);
    audio.request_pin = request_pin;

    pin_clear(audio.request_pin);
}
コード例 #4
0
ファイル: spi.c プロジェクト: CBehling/GimbalController
void spi_close(_SPI *self) {
    *(self->SPIxSTAT) = 0;
    *(self->SPIxCON1) = 0;
    *(self->SPIxCON2) = 0;
    if (self->MISO) {
        __builtin_write_OSCCONL(OSCCON&0xBF);
        *(self->MISOrpinr) |= 0x3F<<(self->MISOrpshift);
        __builtin_write_OSCCONL(OSCCON|0x40);
        self->MISO->owner = NULL;
        pin_digitalIn(self->MISO);
        self->MISO = NULL;
    }
    if (self->MOSI) {
        __builtin_write_OSCCONL(OSCCON&0xBF);
        *(self->MOSI->rpor) &= ~(0x3F<<(self->MOSI->rpshift));
        __builtin_write_OSCCONL(OSCCON|0x40);
        self->MOSI->owner = NULL;
        pin_digitalOut(self->MOSI);
        pin_set(self->MOSI);
        self->MOSI = NULL;
    }
    if (self->SCK) {
        __builtin_write_OSCCONL(OSCCON&0xBF);
        *(self->SCK->rpor) &= ~(0x3F<<(self->SCK->rpshift));
        __builtin_write_OSCCONL(OSCCON|0x40);
        self->SCK->owner = NULL;
        pin_digitalOut(self->SCK);
        pin_clear(self->SCK);
        self->SCK = NULL;
    }
}
コード例 #5
0
// Blit a sprite to screen
void oled_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *buffer) {
  oled_window(x, y, x + w - 1, y + h - 1);

  pin_clear(OLED_NCS);

  pin_clear(OLED_A0);
  SPI_I2S_SendData(OLED_SPI, 0xC);
  oled_wait_spi();
  pin_set(OLED_A0);

  oled_dma((uint8_t*)buffer, (w * h) << 1);
  oled_wait_dma();
  oled_wait_spi();

  pin_set(OLED_NCS);
}
コード例 #6
0
ファイル: encodertest.c プロジェクト: erin-pierce/elecanisms
WORD enc_readReg(WORD address) {
    WORD cmd, result;
    cmd.w = 0x4000|address.w; //set 2nd MSB to 1 for a read
    cmd.w |= parity(cmd.w)<<15; //calculate even parity for

    pin_clear(ENC_NCS);
    spi_transfer(&spi1, cmd.b[1]);
    spi_transfer(&spi1, cmd.b[0]);
    pin_set(ENC_NCS);

    pin_clear(ENC_NCS);
    result.b[1] = spi_transfer(&spi1, 0);
    result.b[0] = spi_transfer(&spi1, 0);
    pin_set(ENC_NCS);
    return result;
}
コード例 #7
0
void init_motor_swing(void){
    dirpin = &D[8];  //set direction control pin as pin 8
    pwmpin = &D[9];  //set PWM pin as pin 9 
    potentiometer = &A[5];  //read potentiometer pin as pin 5
    
    //initialize the two pins as digital outputs and then clear them
    pin_digitalOut(dirpin);
    pin_digitalOut(pwmpin);

    //initialize analog input for potentiometer 
    pin_analogIn(potentiometer);

    pin_clear(dirpin);
    pin_clear(pwmpin);

    oc_pwm(&oc1, pwmpin, &timer5, 1e3, 0);
}
コード例 #8
0
ファイル: imu.c プロジェクト: stevew817/ElecanismsTeam
unsigned char gyro_read(unsigned char address) {
    unsigned char result;
    pin_clear(&GYRO_CS);
    spi_transfer(&spi1, 0x80|(address&0x3F));
    result = spi_transfer(&spi1, 0x00);
    pin_set(&GYRO_CS);
    return result;
}
コード例 #9
0
ファイル: AS5048_erin.c プロジェクト: erin-pierce/elecanisms
void as5048_getRawAngle(_AS5048 *self)
{
	uint8_t MSB;
	uint8_t LSB;
	pin_set(self->CS);	
	MSB=spi_transfer(&spi1,0xFF);
	LSB=spi_transfer(&spi1,0xFF);
	pin_clear(self->CS);
	pin_set(self->CS);		
	MSB=spi_transfer(&spi1,0x00);
	LSB=spi_transfer(&spi1,0x00);
	pin_clear(self->CS);
	MSB=(uint16_t)MSB;
	MSB=MSB<<8;
	MSB|=(uint16_t)LSB;
	self->RawAngle=MSB;	
}
コード例 #10
0
// Pushes n pixels of specific color (to the window)
void oled_push(uint16_t pixel, uint16_t count) {
  pin_clear(OLED_NCS);
  pin_clear(OLED_A0);
  SPI_I2S_SendData(OLED_SPI, 0xC);
  oled_wait_spi();
  pin_set(OLED_A0);
  pixel = ntohs(pixel); // Convert to big-endian
  DMA2_Stream3->CR = repeat_cr; // Have DMA repeat word over and over
  DMA2_Stream3->M0AR = (uint32_t)&pixel;
  DMA2_Stream3->NDTR = count * 2;
  DMA_Cmd(DMA2_Stream3, ENABLE); // Begin transfer
  SPI_I2S_DMACmd(OLED_SPI, SPI_I2S_DMAReq_Tx, ENABLE);
  oled_wait_dma(); // Wait for transfer to finish
  oled_wait_spi();
  DMA2_Stream3->CR = stream_cr; // Restore streaming DMA
  pin_set(OLED_NCS);
}
コード例 #11
0
ファイル: imu.c プロジェクト: stevew817/ElecanismsTeam
unsigned char accel_read(unsigned char address) {
    unsigned char result;
    pin_clear(&ACCEL_CS);
    spi_transfer(&spi1, (address&0x3F)<<1);
    result = spi_transfer(&spi1, 0x00);
    pin_set(&ACCEL_CS);
    return result;
}
コード例 #12
0
ファイル: AS5048_erin.c プロジェクト: erin-pierce/elecanisms
void init_as5048(_AS5048 *self, _Pin *CS)
{
	self->ErrorFlag =0;
	self->RawAngle=0;
	self->CS=CS_pin;

	pin_digitalOut(self->CS);
    pin_clear(self->CS);	
}
コード例 #13
0
void showBlank(void){

    volatile uint8_t segments = 0b00000000;
    volatile uint8_t segmentsZero = 0b00000000;

    int a;
    for(a = 0; a < 3; a++){
        int z;
        for (z = 0 ; z < 8 ; z++){
            volatile uint8_t transferSegment = segments & (1 << (7 - z));
            pin_clear(segmentClock);
            pin_write(segmentData, transferSegment);
            pin_set(segmentClock); 
        }
    } 
    pin_clear(segmentLatch);
    pin_set(segmentLatch);     
}
コード例 #14
0
// Ramps up the 1.8V (directly on = unstable behaviour)
static void oled_vramp(void) {
  const uint32_t count = 2000; // Sony says minimum 500
  for(uint32_t outer = 0; outer < count; outer++) {
    pin_set(OLED_VEN);
    for(uint32_t inner = 0; inner < count; inner++) {
      if(inner == outer) pin_clear(OLED_VEN);
    }
  }
  pin_set(OLED_VEN);
}
コード例 #15
0
ファイル: audio.c プロジェクト: jacobkingery/space_balls
void VendorRequests(void) {
    switch (USB_setup.bRequest) {
        case SEND_SOUND:
            BD[EP0IN].address[0] = audio.play; // set audio to play
            BD[EP0IN].bytecount = 1;    // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            pin_clear(audio.request_pin);
            break;
        default:
            USB_error_flags |= 0x01;    // set Request Error Flag
    }
}
コード例 #16
0
ファイル: mp2.c プロジェクト: jacobkingery/elecanisms_mp2
WORD enc_readReg(WORD address) {
    /*
    Given an address, return the value from the encoder's register at that address
    */
    WORD cmd, result;
    cmd.w = 0x4000|address.w; //set 2nd MSB to 1 for a read
    cmd.w |= parity(cmd.w)<<15; //calculate even parity for

    // Tell the sensor which register we want to read
    pin_clear(ENC_NCS);
    spi_transfer(&spi1, cmd.b[1]);
    spi_transfer(&spi1, cmd.b[0]);
    pin_set(ENC_NCS);

    // Get the reading from the sensor
    pin_clear(ENC_NCS);
    result.b[1] = spi_transfer(&spi1, 0);
    result.b[0] = spi_transfer(&spi1, 0);
    pin_set(ENC_NCS);
    return result;
}
コード例 #17
0
ファイル: launcher.c プロジェクト: jacobkingery/space_balls
void launch_launcher(void) {
    if (launcher.state != launcher.last_state) {  // if we are entering the state, do initialization stuff
        launcher.last_state =  launcher.state;
    }

    if (!pin_read(launcher.load_sensor)) {
        launcher.loaded = 1;
        led_on(&led1);
        pin_clear(launcher.elevator_motor);
    }

    if (launcher.loaded) {
        pin_set(launcher.launch_motor);
        if (!pin_read(launcher.launch_sensor)) {
            limit_flag = 1;
        }

        if (pin_read(launcher.launch_sensor) && limit_flag) {
            limit_counter++;
        }

        if (limit_counter >= 100) {
            launcher.state = rest_launcher;
        }
    } else {
        if (launcher.over) {
            launcher.state = over_launcher;
        }
    }

    if (launcher.state != launcher.last_state) {  // if we are leaving the state, do clean up stuff
        pin_clear(launcher.launch_motor);
        pin_set(launcher.elevator_motor);
        launcher.launch = 0;
        launcher.loaded = 0;
        led_off(&led1);
        limit_flag = 0;
        limit_counter = 0;
    }
}
コード例 #18
0
void showNumber(int value){

    int number = abs(value); 
    int x;

    for(x = 0 ; x < 3; x++){
        int remainder1 = number % 10;
        postNumber(remainder1, 0);
        number /= 10;
    }
    pin_clear(segmentLatch);
    pin_set(segmentLatch); 
}
コード例 #19
0
ファイル: launcher.c プロジェクト: jacobkingery/space_balls
void over_launcher(void) {
    if (launcher.state != launcher.last_state) {  // if we are entering the state, do intitialization stuff
        launcher.last_state = launcher.state;
        pin_clear(launcher.elevator_motor);
    }

    // Check for state transitions
    if (!launcher.over) {
        launcher.state = rest_launcher;
    }
    if (launcher.state != launcher.last_state) {  // if we are leaving the state, do clean up stuff
        led_off(&led1);
        pin_set(launcher.elevator_motor);
    }
}
コード例 #20
0
ファイル: haptic_spring.c プロジェクト: gubbatuba/elecanisms
float PID_control(PID *self) {
    pin_set(DEBUGD0);
    float error = self->set_point - self->position;
    float deriv = (self->position - self->prev_position)/self->dt;
    self->integ_state += error;
    if (self->integ_state > self->integ_max) {
        self->integ_state = self->integ_max;
    } else if (self->integ_state < self->integ_min) {
        self->integ_state = self->integ_min;
    };
    float pterm = self->Kp * error;
    float iterm = self->Ki * self->integ_state;
    float dterm = self->Kd * deriv;
    self->prev_position = self->position;
    pin_clear(DEBUGD0);
    return pterm + iterm + dterm;
}
コード例 #21
0
void postNumber(int number, uint8_t decimal){

    volatile uint8_t segments = 0b00000000;
    volatile uint8_t segmentsZero = 0b00000000;

    #define a  1<<0
    #define b  1<<6
    #define c  1<<5
    #define d  1<<4
    #define e  1<<3
    #define f  1<<1
    #define g  1<<2
    #define dp 1<<7


    switch (number){
        case 1: segments = b | c | segmentsZero; break;
        case 2: segments = a | b | d | e | g | segmentsZero; break;
        case 3: segments = a | b | c | d | g | segmentsZero; break;
        case 4: segments = f | g | b | c | segmentsZero; break;
        case 5: segments = a | f | g | c | d | segmentsZero; break;
        case 6: segments = a | f | g | e | c | d | segmentsZero; break;
        case 7: segments = a | b | c | segmentsZero; break;
        case 8: segments = a | b | c | d | e | f | g | segmentsZero; break;
        case 9: segments = a | b | c | d | f | g | segmentsZero; break;
        case 0: segments = a | b | c | d | e | f | segmentsZero; break;
        case ' ': segments = 0 | segmentsZero; break;
        case 'c': segments = g | e | d | segmentsZero; break;
        case '-': segments = g | segmentsZero; break;
    }

    if (decimal == 1){
        segments |= dp;
    }
    int y;
    for (y = 0 ; y < 8 ; y++){
        volatile uint8_t transferSegment = segments & (1 << (7 - y));
        pin_clear(segmentClock);
        pin_write(segmentData, transferSegment);
        pin_set(segmentClock); 
    }
}
コード例 #22
0
ファイル: imu.c プロジェクト: stevew817/ElecanismsTeam
void gyro_get_measurements(int16_t *x, int16_t *y, int16_t *z) {
	//ATTN gyro
	pin_clear(&GYRO_CS);
	
	//start reading from XL, with auto-increment
	spi_transfer(&spi1, 0b11000000 | OUT_X_L);
	*x  = ((int16_t) (spi_transfer(&spi1, 0))) & 0x00FF;
	//XH
	*x |= spi_transfer(&spi1, 0) << 8;
	//YL
	*y  = ((int16_t) (spi_transfer(&spi1, 0))) & 0x00FF;
	//YH
	*y |= spi_transfer(&spi1, 0) << 8;
	//ZL
	*z  = ((int16_t) (spi_transfer(&spi1, 0))) & 0x00FF;
	//ZH
	*z |= spi_transfer(&spi1, 0) << 8;
	
	pin_set(&GYRO_CS);
}
コード例 #23
0
ファイル: launcher.c プロジェクト: jacobkingery/space_balls
void rest_launcher(void) {
    if (launcher.state != launcher.last_state) {  // if we are entering the state, do intitialization stuff
        launcher.last_state = launcher.state;
    }

    if (!pin_read(launcher.load_sensor)) {
        launcher.loaded = 1;
        led_on(&led1);
        pin_clear(launcher.elevator_motor);
    }

    if (launcher.over) {
        launcher.state = over_launcher;
    }

    if (launcher.launch) {
        launcher.state = launch_launcher;
    }

    /*if (state_launcher != last_state_launcher) {  // if we are leaving the state, do clean up stuff
      }*/
}
コード例 #24
0
ファイル: entry.c プロジェクト: AbdFatah/physical-web
void entry(void)
{
	int8_t tag_angle;

	/* set advertisment packet */
	radio_advertise(&g_beacon_pkt, sizeof(g_beacon_pkt));
	/* run advertisement in background every 995ms */
	radio_interval_ms(995);

	/* infinite foreground loop */
	while(TRUE)
	{
		/* get tag angle from 3D accelerometer */
		acc_magnitude(&tag_angle);
		/* only tx while beacon is worn (facing forward +/-45 degree) */
		radio_enable(abs(tag_angle)<45);

		/* blink once every three seconds */
		timer_wait_ms(3000);
		pin_set(CONFIG_LED_PIN);
		timer_wait_ms(1);
		pin_clear(CONFIG_LED_PIN);
	}
}
コード例 #25
0
ファイル: spi.c プロジェクト: CBehling/GimbalController
void spi_open(_SPI *self, _PIN *MISO, _PIN *MOSI, _PIN *SCK, float freq) {
    uint16_t primary, secondary;

    if ((MISO->rpnum==-1) || (MOSI->rpnum==-1) || (SCK->rpnum==-1))
        return; // At least one of the specified pins is not an RP pin
    if ((MISO->owner==NULL) && (MOSI->owner==NULL) && (SCK->owner==NULL)) {
        // All of the specified pins are available and RP pins, so configure 
        // as specified
        pin_digitalIn(MISO);
        pin_digitalOut(MOSI);
        pin_set(MOSI);
        pin_digitalOut(SCK);
        pin_clear(SCK);
        self->MISO = MISO;
        MISO->owner = (void *)self;
        MISO->write = NULL;
        MISO->read = NULL;
        self->MOSI = MOSI;
        MOSI->owner = (void *)self;
        MOSI->write = NULL;
        MOSI->read = NULL;
        self->SCK = SCK;
        SCK->owner = (void *)self;
        SCK->write = NULL;
        SCK->read = NULL;
        __builtin_write_OSCCONL(OSCCON&0xBF);
        *(self->MISOrpinr) &= ~(0x3F<<(self->MISOrpshift));
        *(self->MISOrpinr) |= (MISO->rpnum)<<(self->MISOrpshift);
        *(MOSI->rpor) &= ~(0x3F<<(MOSI->rpshift));
        *(MOSI->rpor) |= (self->MOSIrpnum)<<(MOSI->rpshift);
        *(SCK->rpor) &= ~(0x3F<<(SCK->rpshift));
        *(SCK->rpor) |= (self->SCKrpnum)<<(SCK->rpshift);
        __builtin_write_OSCCONL(OSCCON|0x40);
    } else if ((self->MISO!=MISO) || (self->MOSI!=MOSI) || (self->SCK!=SCK)) {
        return; // At least one of the specified pins does not match the 
                // previous assignment
    }
    // Clip freq to be in allowable range of values
    if (freq>(FCY/2.))
        freq = FCY/2.;
    if (freq<(FCY/(64.*8.)))
        freq = FCY/(64.*8.);
    // Select primary prescale bits
    if (freq<=(FCY/(2.*64.))) {
        freq *= 64.;
        primary = 0;    // Set primary prescale bits for 64:1
    } else if (freq<=(FCY/(2.*16.))) {
        freq *= 16.;
        primary = 1;    // Set primary prescale bits for 16:1
    } else if (freq<=(FCY/(2.*4.))) {
        freq *= 4.;
        primary = 2;    // Set primary prescale bits for 4:1
    } else {
        primary = 3;    // Set primary prescale bits for 1:1
    }
    // Compute secondary prescale value to get closest SPI clock freq to that 
    // specified
    secondary = (uint16_t)(0.5+FCY/freq);
    secondary = (8-secondary)<<2;   // Map secondary prescale bits for SPIxCON1
    // Configure the SPI module
    //   set SPI module to 8-bit master mode
    //   set SMP = 0, CKE = 1, and CKP = 0
    //   set SPRE and PPRE bits to get the closest SPI clock freq to that 
    //   specified
    *(self->SPIxCON1) = 0x0120|primary|secondary;
    *(self->SPIxCON2) = 0;
    // Enable the SPI module and clear status flags
    *(self->SPIxSTAT) = 0x8000;
}
コード例 #26
0
ファイル: core_handlers.c プロジェクト: areben/ROCKETuC
int handle_packet_pin_control(unsigned char length, unsigned char *data)
{
	int s = PACKET_STAT_OK;

	// check if length matches for packet-data
	if(length != 2) {
		send_status_packet(PACKET_RETURN_INAVLID_DATA);
		return PACKET_STAT_ERR_DATA;
	}

	packet_data_in_pin_control *pd = (packet_data_in_pin_control *)&data[0];

	switch(pd->control) {
		case PIN_CONTROL_CLEAR:
			if((s = pin_clear(pd->pin)) != PACKET_STAT_OK) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				send_status_packet(PACKET_RETURN_ACK);
			}
			break;
		case PIN_CONTROL_SET:
			if((s = pin_set(pd->pin)) != PACKET_STAT_OK) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				send_status_packet(PACKET_RETURN_ACK);
			}
			break;
		case PIN_CONTROL_TOGGLE:
			if((s = pin_toggle(pd->pin)) != PACKET_STAT_OK) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				send_status_packet(PACKET_RETURN_ACK);
			}
			break;
		case PIN_CONTROL_DIGITAL_READ:
			if((s = pin_digital_read(pd->pin)) < 0) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				packet_data_out_digital_pin_read *pdo = (packet_data_out_digital_pin_read *)&outp.data[0];

				outp.start	= PACKET_OUTBOUND_START;
				outp.length	= 6;
				outp.type 	= PACKET_OUT_DIGITAL_PIN_READ;
	
				pdo->pin   = pd->pin;
				pdo->state = s;

				outp.crc = packet_calc_crc(&outp);

				packet_send(&outp);
			}
			break;
		case PIN_CONTROL_ANALOG_READ:
			if((s = pin_analog_read(pd->pin)) < 0) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				packet_data_out_analog_pin_read *pdo = (packet_data_out_analog_pin_read *)&outp.data[0];

				outp.start	= PACKET_OUTBOUND_START;
				outp.length	= 7;
				outp.type 	= PACKET_OUT_ANALOG_PIN_READ;
	
				pdo->pin       = pd->pin;
				pdo->value_lsb = (0x00FF & s);
				pdo->value_msb = (0x0F00 & s) >> 8;

				outp.crc = packet_calc_crc(&outp);

				packet_send(&outp);
			}
			break;
		case PIN_CONTROL_PULSELENGTH_READ:
			if((s = pin_pulselength_read(pd->pin)) < 0) {
				send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			}
			else {
				packet_data_out_pulselength_read *pdo = 
							( packet_data_out_pulselength_read *)&outp.data[0];

				outp.start	= PACKET_OUTBOUND_START;
				outp.length	= 7;
				outp.type 	= PACKET_OUT_PULSELENGHT_READ;
	
				pdo->pin   = pd->pin;
				pdo->value_lsb = (0x00FF & s);
				pdo->value_msb = (0x7F00 & s) >> 8;

				outp.crc = packet_calc_crc(&outp);

				packet_send(&outp);
			}
			break;
		default:
			send_status_packet(PACKET_RETURN_INVALID_PIN_COMMAND);
			s = PACKET_STAT_ERR_DATA;
	}

	return s;
}
コード例 #27
0
ファイル: main.c プロジェクト: areben/ROCKETuC
int main(void)
{
	clock_init();

	pin_reserve(PIN_1_1);
	pin_reserve(PIN_1_2);

	serial_init(9600);

	cio_print("** ROCKETuC - librocketcore PIN test **\n\r");

	dump_regs("initial");

	// invalid port
	if(pin_setup(0x30, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPORT) {
		cio_print("0x30 is an invalid port\n\r");
	}
	
	// invalid pin
	if(pin_setup(0x2A, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) {
		cio_print("0x2A is an invalid pin\n\r");
	}

	// P1.1 + P1.2 are reserved for UART1
	if(pin_setup(PIN_1_1, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) {
		cio_print("0x11 is an invalid (reserved) pin\n\r");
	}
	if(pin_setup(PIN_1_2, PIN_FUNCTION_OUTPUT) == PIN_STAT_ERR_INVALPIN) {
		cio_print("0x12 is an invalid (reserved) pin\n\r");
	}

	// pins on port 2 do not support ADC
	int p;

	for(p = 0; p < 8; p++) { 
		if(pin_setup(PIN_2_0 + p, PIN_FUNCTION_ANALOG_IN) == PIN_STAT_ERR_UNSUPFUNC) {
			cio_printf("0x2%i does not support ADC\n\r", p);
		}
	}
	
	// set P1.0 + P1.6 + P2.5 to output (the build in LEDs)
	pin_setup(PIN_1_0, PIN_FUNCTION_OUTPUT);
	pin_setup(PIN_1_6, PIN_FUNCTION_OUTPUT);
	pin_setup(PIN_2_5, PIN_FUNCTION_OUTPUT);

	
	dump_regs("p1.0+p1.6+p2.5 output");

	// set P1.0 + P1.6 + P2.5 to HIGH
	pin_set(PIN_1_0);
	pin_set(PIN_1_6);
	pin_set(PIN_2_5);

	dump_regs("p1.0+p1.6+p2.5 set");

	// read P1.0 + P1.6 + p2.5 states
	cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0));	
	cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6));	
	cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5));	
	
	// clear P1.0 + p1.6 + p2.5 to LOW 
	pin_clear(PIN_1_0);
	pin_clear(PIN_1_6);
	pin_clear(PIN_2_5);

	dump_regs("p1.0+p1.6+p2.5 clear");

	// read P1.0 + P1.6 + 2.5 states
	cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0));	
	cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6));	
	cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5));	

	// toggle P1.0 + P1.6 + P2.5
	pin_toggle(PIN_1_0);
	pin_toggle(PIN_1_6);
	pin_toggle(PIN_2_5);

	dump_regs("p1.0+p1.6+p2.5 toggle");

	// read P1.0 + P1.6 states
	cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0));	
	cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6));	
	cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5));	

	// toggle P1.0 + P1.6 + P2.5
	pin_toggle(PIN_1_0);
	pin_toggle(PIN_1_6);
	pin_toggle(PIN_2_5);

	dump_regs("p1.0+p1.6+p2.5 toggle");

	// read P1.0 + P1.6 states
	cio_printf("P1.0 is %x\n\r", pin_digital_read(PIN_1_0));	
	cio_printf("P1.6 is %x\n\r", pin_digital_read(PIN_1_6));	
	cio_printf("P2.5 is %x\n\r", pin_digital_read(PIN_2_5));	

	// set P1.3 to input float
	pin_setup(PIN_1_3, PIN_FUNCTION_INPUT_FLOAT);

	dump_regs("p1.3 input float");

	cio_print("Press button on P1.3 to continue ...");

	while(pin_digital_read(PIN_1_3)) __asm__("nop");

	cio_print(" OK\n\r");
	
	// set P2.3 to input pull-down 
	pin_setup(PIN_2_3, PIN_FUNCTION_INPUT_PULLDOWN);

	dump_regs("p2.3 input pull-down");

	cio_print("Press button on P2.3 to continue ...");

	while(!pin_digital_read(PIN_2_3)) __asm__("nop");

	cio_print(" OK\n\r");
	
	// set P2.4 to input pull-down 
	pin_setup(PIN_2_4, PIN_FUNCTION_INPUT_PULLUP);

	dump_regs("p2.4 input pull-up");

	cio_print("Press button on P2.4 to continue ...");

	while(pin_digital_read(PIN_2_4)) __asm__("nop");

	cio_print(" OK\n\r");

	int pl = 0;

	cio_print("Press button on P1.3 for pulselength read ...");

	delay(50000);

	pl = pin_pulselength_read(PIN_1_3);

	cio_printf(" OK, pl=%i\n\r", pl);

	cio_print("Press button on P2.3 for pulselength read ...");

	delay(50000);

	pl = pin_pulselength_read(PIN_2_3);

	cio_printf(" OK, pl=%i\n\r", pl);

	cio_print("Press button on P2.4 for pulselength read ...");

	delay(50000);

	pl = pin_pulselength_read(PIN_2_4);

	cio_printf(" OK, pl=%i\n\r", pl);
	
	pin_set(PIN_1_0);
	pin_clear(PIN_1_6);
	pin_clear(PIN_2_5);

	// set P1.5 to analog in
	int i = 0;

	cio_printf("setup 1.5 for analog in: %i\n\r", pin_setup(PIN_1_5, PIN_FUNCTION_ANALOG_IN));
	dump_regs("p1.5 analog in");
	
	int adcin1 = pin_analog_read(PIN_1_5); 
	int adcin2 = 0; 
	cio_printf("Analog read p1.5: %x\n\r", adcin1);

	// set P2.2 to PWM with period of 20ms and duty cycle of 7.5%
	cio_printf("setup 2.2 for PWM: %i\n\r", pin_setup(PIN_2_2, PIN_FUNCTION_PWM));
	dump_regs("p2.2 PWM");

	// only one of the two possible pins on port two are allowed to be set to PWM
	cio_printf("setup 2.1 for PWM: %i\n\r", pin_setup(PIN_2_1, PIN_FUNCTION_PWM));

	// period 
	pin_pwm_function(PIN_2_2, 20000);
	pin_pwm_control(PIN_2_2, adc2dc(adcin1));

	while (1) {
		delay();

		pin_toggle(PIN_1_0);
		pin_toggle(PIN_1_6);

		if(i++ % 2 == 0) {
			pin_toggle(PIN_2_5);
		}

		if(!pin_digital_read(PIN_1_3)) {
			pin_toggle(PIN_1_6);
			while(!pin_digital_read(PIN_1_3)) __asm__("nop");
		}

		adcin2 = pin_analog_read(PIN_1_5); 

		// only output ADC value if delta was more then 5
		if(adcin2 - adcin1 > 5 || adcin1 - adcin2 > 5) {
			adcin1 = adcin2;
			cio_printf("Analog read at p1.5: %x (%i)\n\r", adcin2, adcin2);
			pin_pwm_control(PIN_2_2, adc2dc(adcin1));
		}
	}

	return 0;
}
コード例 #28
0
ファイル: imu.c プロジェクト: stevew817/ElecanismsTeam
void gyro_write(unsigned char address, unsigned char value){
    pin_clear(&GYRO_CS);
    spi_transfer(&spi1, address&0x3F);
    spi_transfer(&spi1, value&0xFF);
    pin_set(&GYRO_CS);
}
コード例 #29
0
void clear_dirpin(void){
    pin_clear(dirpin);    
}
コード例 #30
0
ファイル: imu.c プロジェクト: stevew817/ElecanismsTeam
void accel_write(unsigned char address, unsigned char value) {
    pin_clear(&ACCEL_CS);
    spi_transfer(&spi1, 0x80|((address&0x3F)<<1));
    spi_transfer(&spi1,value&0xFF);
    pin_set(&ACCEL_CS);
}