spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 #include "revo_f4.h"
35 
36 #include "gpio.h"
37 
38 class SPI
39 {
40 
41 public:
42 
43  void init(const spi_hardware_struct_t *conf);
44  void set_divisor(uint16_t new_divisor);
45 
46  void enable(GPIO& cs);
47  void disable(GPIO& cs);
48 
49  bool transfer(uint8_t *out_data, uint32_t num_bytes, uint8_t* in_data, GPIO* cs = NULL, void (*cb)(void) = NULL);
50  bool write(const uint8_t *out_data, uint32_t num_bytes, GPIO* cs = NULL);
51  uint8_t transfer_byte(uint8_t data, GPIO* cs = NULL);
52 
53  void transfer_complete_cb();
54  inline bool is_busy() {return busy_;}
55 
56 private:
57 
58  void perform_transfer();
59  uint8_t* in_buffer_ptr_;
60  const uint8_t* out_buffer_ptr_;
61  uint32_t num_bytes_;
62 
67 
69 
70  uint32_t errors_ = 0;
72  volatile bool busy_ = false;
73  void (*transfer_cb_)(void) = NULL;
74 };
void transfer_complete_cb()
Definition: spi.cpp:253
uint32_t num_bytes_
Definition: spi.h:61
GPIO sck_
Definition: spi.h:66
DMA Init structure definition.
Definition: stm32f4xx_dma.h:54
Definition: spi.h:38
void enable(GPIO &cs)
Definition: spi.cpp:148
const spi_hardware_struct_t * c_
Definition: spi.h:63
bool transfer(uint8_t *out_data, uint32_t num_bytes, uint8_t *in_data, GPIO *cs=NULL, void(*cb)(void)=NULL)
Definition: spi.cpp:203
void(* transfer_cb_)(void)
Definition: spi.h:73
bool write(const uint8_t *out_data, uint32_t num_bytes, GPIO *cs=NULL)
Definition: spi.cpp:187
const uint8_t * out_buffer_ptr_
Definition: spi.h:60
GPIO * cs_
Definition: spi.h:71
GPIO miso_
Definition: spi.h:65
static void cb(uint8_t result)
Definition: ms4525.cpp:36
bool is_busy()
Definition: spi.h:54
volatile bool busy_
Definition: spi.h:72
uint8_t transfer_byte(uint8_t data, GPIO *cs=NULL)
Definition: spi.cpp:156
GPIO mosi_
Definition: spi.h:64
void set_divisor(uint16_t new_divisor)
Definition: spi.cpp:109
uint8_t * in_buffer_ptr_
Definition: spi.h:59
Definition: gpio.h:37
DMA_InitTypeDef DMA_InitStructure_
Definition: spi.h:68
void perform_transfer()
Definition: spi.cpp:218
void init(const spi_hardware_struct_t *conf)
Definition: spi.cpp:40
#define NULL
Definition: usbd_def.h:50
uint32_t errors_
Definition: spi.h:70
void disable(GPIO &cs)
Definition: spi.cpp:152


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19