Subversion Repositories Projects

Rev

Rev 2039 | Rev 2225 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2039 Rev 2099
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2014 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2015 by Claas Anders "CaScAdE" Rathje               *
3
 *   admiralcascade@gmail.com                                               *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
19
 ****************************************************************************/
20
 
20
 
21
#ifndef _SPI_H
21
#ifndef _SPI_H
22
#define _SPI_H
22
#define _SPI_H
23
 
23
 
24
/*
24
/*
25
 * structs 'n union for easy SPI transfer
25
 * structs 'n union for easy SPI transfer
26
 */
26
 */
27
typedef struct {
27
typedef struct {
28
    int16_t ampere;
28
    int16_t ampere;
29
    int32_t mah;
29
    int32_t mah;
30
    int16_t volt;
30
    int16_t volt;
31
} __attribute__((packed)) SPI_strom_data_t;
31
} __attribute__((packed)) SPI_strom_data_t;
32
 
32
 
33
typedef struct {
33
typedef struct {
34
    uint8_t c[10];
34
    uint8_t c[10];
35
    uint8_t chk;
35
    uint8_t chk;
36
} __attribute__((packed)) SPI_char_buffer_t;
36
} __attribute__((packed)) SPI_char_buffer_t;
37
 
37
 
38
union SPI_buffer_t {
38
union SPI_buffer_t {
39
    SPI_strom_data_t data;
39
    SPI_strom_data_t data;
40
    SPI_char_buffer_t buffer;
40
    SPI_char_buffer_t buffer;
41
};
41
};
42
 
42
 
43
volatile union SPI_buffer_t SPI_buffer;
43
volatile union SPI_buffer_t SPI_buffer;
44
 
44
 
45
/**
45
/**
46
 * SPI interrupt handler
46
 * SPI interrupt handler
47
 */
47
 */
48
ISR(SPI_STC_vect);
48
ISR(SPI_STC_vect);
49
 
49
 
50
/**
50
/**
51
 * init the SPI as master
51
 * init the SPI as master
52
 */
52
 */
53
void SpiMasterInit(void);
53
void SpiMasterInit(void);
54
 
54
 
55
/**
55
/**
56
 * check if SPI transfer is still busy
56
 * check if SPI transfer is still busy
57
 */
57
 */
58
int TransferIsBusy(void);
58
int TransferIsBusy(void);
59
 
59
 
60
/**
60
/**
61
 * start a new transfer with length <len>
61
 * start a new transfer with length <len>
62
 */
62
 */
63
void StartTransfer(uint16_t);
63
void StartTransfer(uint16_t);
64
 
64
 
65
/**
65
/**
66
 * send next command through spi
66
 * send next command through spi
67
 */
67
 */
68
void spi_send_next();
68
void spi_send_next();
69
 
69
 
70
#endif
70
#endif
71
 
71