include/spi.h
author Tero Marttila <terom@paivola.fi>
Wed, 08 Oct 2014 23:20:19 +0300
changeset 10 d485c5b3ab4d
permissions -rw-r--r--
spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
10
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     1
#ifndef QMSK_SPI_H
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     2
#define QMSK_SPI_H
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     3
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     4
#include "stdlib.h"
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     5
#include "port.h"
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     6
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     7
static ioport_t *const SPI_DDR = &DDRB;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     8
static ioport_t *const SPI_PORT = &PORTB;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     9
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    10
static const byte SPI_SCK   = PORTB5;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    11
static const byte SPI_MISO  = PORTB4;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    12
static const byte SPI_MOSI  = PORTB3;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    13
static const byte SPI_SS    = PORTB2;
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    14
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    15
enum spi_dord {
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    16
    SPI_DORD_MSB        = 0b0,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    17
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    18
    SPI_DORD            = SPI_DORD_MSB
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    19
};
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    20
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    21
enum spi_cpol {
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    22
    SPI_CPOL_0 = 0b0,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    23
    SPI_CPOL_1 = 0b1,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    24
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    25
    SPI_CPOL   = SPI_CPOL_1 // mode 3
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    26
};
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    27
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    28
enum spi_cpha {
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    29
    SPI_CPHA_0  = 0b0,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    30
    SPI_CPHA_1  = 0b1,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    31
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    32
    SPI_CPHA   = SPI_CPHA_1 // mode 3
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    33
};
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    34
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    35
enum spi_clock {
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    36
    SPI_CLOCK_4         = 0b000,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    37
    SPI_CLOCK_16        = 0b001,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    38
    SPI_CLOCK_64        = 0b010,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    39
    SPI_CLOCK_128       = 0b011,
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    40
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    41
    SPI_CLOCK           = SPI_CLOCK_16
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    42
};
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    43
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    44
#define SPI_COUNT 2
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    45
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    46
/*
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    47
 * Initialize in SPI master mode.
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    48
 */
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    49
void spi_init ();
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    50
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    51
/*
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    52
 * Write out value, and return read value.
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    53
 */
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    54
byte spi_readwrite (byte value);
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    55
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    56
/*
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    57
 * Perform an SPI bus update.
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    58
 */
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    59
void spi_update ();
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    60
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    61
void spi_set (byte index, byte value);
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    62
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    63
byte spi_get (byte index);
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    64
d485c5b3ab4d spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    65
#endif