예제 #1
0
파일: spi_max7219.c 프로젝트: 4refr0nt/mraa
int
main(int argc, char** argv)
{
    //! [Interesting]
    mraa_spi_context spi;
    spi = mraa_spi_init(1);
    if (spi == NULL) {
        printf("Initialization of spi failed, check syslog for details, exit...\n");
        exit(1);
    }

    printf("SPI initialised successfully\n");

    mraa_spi_frequency(spi, 400000);
    mraa_spi_lsbmode(spi, 0);

    // The MAX7219/21 Chip needs the data in word size
    if (mraa_spi_bit_per_word(spi, 16) != MRAA_SUCCESS) {
        printf("Could not set SPI Device to 16Bit mode, exit...\n");
        exit(1);
    };

    mraa_spi_write_word(spi, 0x0900); // Do not decode bits
    mraa_spi_write_word(spi, 0x0a05); // Brightness of LEDs
    mraa_spi_write_word(spi, 0x0b07); // Show all Scan Lines
    mraa_spi_write_word(spi, 0x0c01); // Display on
    mraa_spi_write_word(spi, 0x0f00); // Testmode off

    // Display Pattern on the display
    uint16_t dataAA55[] = { 0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855 };
    mraa_spi_write_buf_word(spi, dataAA55, 16);

    sleep(2);

    // Display inverted Pattern
    uint16_t data55AA[] = { 0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa };
    mraa_spi_write_buf_word(spi, data55AA, 16);

    sleep(2);

    // Clear the display
    uint16_t data[] = { 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800 };
    mraa_spi_write_buf_word(spi, data, 16);

    int i;
    int j;
    // cycle through all LED's
    for (i = 1; i <= 8; i++) {
        for (j = 0; j < 8; j++) {
            mraa_spi_write_word(spi, (i << 8) + (1 << j));
            sleep(1);
        }
        mraa_spi_write_word(spi, i << 8);
    }

    mraa_spi_stop(spi);

    //! [Interesting]
}
예제 #2
0
void Adafruit_STMPE610::end(void) {
    // hardware SPI
    if (SPI)
        mraa_spi_stop(SPI);
    if (_gpioCS)
        mraa_gpio_close(_gpioCS);
    DestroyTransaction();

}
예제 #3
0
파일: LcdDriver.c 프로젝트: chen1990/wsnlab
void Display_Stop(void)
{
  //reset all GPIOs to '0'
  mraa_gpio_write(SCS, 0);
  mraa_gpio_write(VDD, 0);
  //close all GPIOs
  mraa_gpio_close(SCS);
  mraa_gpio_close(VDD);
  //close all Peripherals
  mraa_spi_stop(spi);
  mraa_pwm_close(pwm);
}
예제 #4
0
파일: kx122.c 프로젝트: g-vidal/upm
void kx122_close(kx122_context dev)
{
  assert(dev != NULL);
  kx122_uninstall_isr(dev,INT1);
  kx122_uninstall_isr(dev,INT2);

  if(dev->i2c){
    mraa_i2c_stop(dev->i2c);
  }
  if(dev->spi){
    mraa_spi_stop(dev->spi);
  }
  if(dev->chip_select){
    mraa_gpio_close(dev->chip_select);
  }
  free(dev);
}
예제 #5
0
파일: lis3dh.c 프로젝트: g-vidal/upm
void
lis3dh_close(lis3dh_context dev)
{
    assert(dev != NULL);

    lis3dh_uninstall_isr(dev, LIS3DH_INTERRUPT_INT1);
    lis3dh_uninstall_isr(dev, LIS3DH_INTERRUPT_INT2);

    if (dev->i2c) {
        mraa_i2c_stop(dev->i2c);
    }

    if (dev->spi) {
        mraa_spi_stop(dev->spi);
    }

    if (dev->gpioCS) {
        mraa_gpio_close(dev->gpioCS);
    }

    free(dev);
}
예제 #6
0
파일: spi.c 프로젝트: KurtE/mraa
int
main(int argc, char** argv)
{
    mraa_result_t status = MRAA_SUCCESS;
    mraa_spi_context spi;
    int i, j;

    /* initialize mraa for the platform (not needed most of the times) */
    mraa_init();

    //! [Interesting]
    /* initialize SPI bus */
    spi = mraa_spi_init(SPI_BUS);
    if (spi == NULL) {
        fprintf(stderr, "Failed to initialize SPI\n");
        mraa_deinit();
        return EXIT_FAILURE;
    }

    /* set SPI frequency */
    status = mraa_spi_frequency(spi, SPI_FREQ);
    if (status != MRAA_SUCCESS)
        goto err_exit;

    /* set big endian mode */
    status = mraa_spi_lsbmode(spi, 0);
    if (status != MRAA_SUCCESS) {
        goto err_exit;
    }

    /* MAX7219/21 chip needs the data in word size */
    status = mraa_spi_bit_per_word(spi, 16);
    if (status != MRAA_SUCCESS) {
        fprintf(stdout, "Failed to set SPI Device to 16Bit mode\n");
        goto err_exit;
    }

    /* do not decode bits */
    mraa_spi_write_word(spi, 0x0900);

    /* brightness of LEDs */
    mraa_spi_write_word(spi, 0x0a05);

    /* show all scan lines */
    mraa_spi_write_word(spi, 0x0b07);

    /* set display on */
    mraa_spi_write_word(spi, 0x0c01);

    /* testmode off */
    mraa_spi_write_word(spi, 0x0f00);

    while (flag) {
        /* set display pattern */
        mraa_spi_write_buf_word(spi, pat, 16);

        sleep(2);

        /* set inverted display pattern */
        mraa_spi_write_buf_word(spi, pat_inv, 16);

        sleep(2);

        /* clear the LED's */
        mraa_spi_write_buf_word(spi, pat_clear, 16);

        /* cycle through all LED's */
        for (i = 1; i <= 8; i++) {
            for (j = 0; j < 8; j++) {
                mraa_spi_write_word(spi, (i << 8) + (1 << j));
                sleep(1);
            }
            mraa_spi_write_word(spi, i << 8);
        }
    }

    /* stop spi */
    mraa_spi_stop(spi);

    //! [Interesting]
    /* deinitialize mraa for the platform (not needed most of the times) */
    mraa_deinit();

    return EXIT_SUCCESS;

err_exit:
    mraa_result_print(status);

    /* stop spi */
    mraa_spi_stop(spi);

    /* deinitialize mraa for the platform (not needed most of the times) */
    mraa_deinit();

    return EXIT_FAILURE;
}
예제 #7
0
파일: spi.hpp 프로젝트: smuellener/mraa
 /**
  * Closes spi bus
  */
 ~Spi()
 {
     mraa_spi_stop(m_spi);
 }
예제 #8
0
int main(int argc, char **argv)
{
	printf("-------------------------------------------------------\n");
	printf("Welcome to SHARP Memory Display demo using Intel Edison\n");
	printf("-------------------------------------------------------\n");
	sleep(1);
	
	signal(SIGINT, &sig_handler);
	
	GPIO_Init();
	sleep(1);
	SPI_Init();
	sleep(1);
	PWM_Init();
	sleep(1);
	
	PWM_Run(); 
	
	Display_Init();
	printf("SHARP Display initialized\n");
	
	while(isrunning)
	{
		//Loop Forever
                Display_Init();
		printf("UNI FREIBURG\n");
		Display_Image("Uni_Freiburg");
		sleep(5);

                Display_Init();
                printf("INTEL ATOM\n");
		Display_Image("Intel_Atom");
		sleep(5);

                Display_Init();
                printf("NIKOLA TESLA\n");
		Display_Image("Nikola_Tesla");
		sleep(5);

                Display_Init();
                printf("ALBERT EINSTEIN\n");
		Display_Image("Albert_Einstein");
		sleep(5);

                Display_Init();
                printf("WHITE TIGER\n");
		Display_Image("White_Tiger");
		sleep(5);
		
                Display_Init();
                printf("WALL-E\n");
		Display_Image("Wall_E");
		sleep(5);
	}
	
	//reset all GPIOs to '0'
	mraa_gpio_write(SCS, 0);
	
	//close all GPIOs
	mraa_gpio_close(SCS);
	
	//close all Peripherals
	mraa_spi_stop(spi);
	mraa_pwm_close(pwm);
	
	fprintf(stdout, "\nSHARP Display exited\n");
	
	return MRAA_SUCCESS;
}