Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual
Page 44

KTD-S0057-I
Page 40 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
Now the corresponding test program (needs root rights):
/* SPI test program for
* Electronic Assembly graphic module eDIP128-6
* Copyright (c) 2013 Kontron Technology A/S
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define SPI_OPEN_ERROR
0x10
#define SPI_MODE_ERROR
0x11
#define SPI_BITS_ERROR
0x12
#define SPI_SPEED_ERROR
0x13
static const char *device = "/dev/spidev3.0";
/****** Do not forget to enable SPI3 (= spidev4.0) in U-Boot Setup ******/
/*static const char *device = "/dev/spidev4.0";*/
static uint8_t mode = 3;
static uint8_t bits
= 8;
static uint32_t speed = 100000;
static uint16_t delay = 10;
static int fd;
static int transmit_spi_test_string (void)
{
uint8_t tx[] = {
0x11,
/* DC1 */
0x05,
/* Data len */
0x48, 0x65, 0x6C, 0x6C, 0x6F,
/* Data = 'Hello' */
0x0A
/* Checksum */
};
struct spi_ioc_transfer xfer = {
.tx_buf = (unsigned long) tx,
.rx_buf = (unsigned long) NULL,
.len = ARRAY_SIZE(tx),
.delay_usecs = delay,
.speed_hz = 0,
.bits_per_word = 0 };
if (ioctl (fd, SPI_IOC_MESSAGE (1), &xfer) == 1)
return
-1;
return
0;
}