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 "gpio.h"
35 #include "revo_f4.h"
36 
37 class SPI
38 {
39 public:
40  void init(const spi_hardware_struct_t* conf);
41  void set_divisor(uint16_t new_divisor);
42 
43  void enable(GPIO& cs);
44  void disable(GPIO& cs);
45 
46  bool transfer(uint8_t* out_data, uint32_t num_bytes, uint8_t* in_data, GPIO* cs = NULL, void (*cb)(void) = NULL);
47  bool write(const uint8_t* out_data, uint32_t num_bytes, GPIO* cs = NULL);
48  uint8_t transfer_byte(uint8_t data, GPIO* cs = NULL);
49 
50  void transfer_complete_cb();
51  inline bool is_busy() { return busy_; }
52 
53 private:
54  void perform_transfer();
55  uint8_t* in_buffer_ptr_;
56  const uint8_t* out_buffer_ptr_;
57  uint32_t num_bytes_;
58 
63 
65 
66  uint32_t errors_ = 0;
68  volatile bool busy_ = false;
69  void (*transfer_cb_)(void) = NULL;
70 };
void transfer_complete_cb()
Definition: spi.cpp:254
uint32_t num_bytes_
Definition: spi.h:57
GPIO sck_
Definition: spi.h:62
DMA Init structure definition.
Definition: stm32f4xx_dma.h:54
Definition: spi.h:37
void enable(GPIO &cs)
Definition: spi.cpp:150
const spi_hardware_struct_t * c_
Definition: spi.h:59
bool transfer(uint8_t *out_data, uint32_t num_bytes, uint8_t *in_data, GPIO *cs=NULL, void(*cb)(void)=NULL)
Definition: spi.cpp:206
void(* transfer_cb_)(void)
Definition: spi.h:69
bool write(const uint8_t *out_data, uint32_t num_bytes, GPIO *cs=NULL)
Definition: spi.cpp:191
const uint8_t * out_buffer_ptr_
Definition: spi.h:56
GPIO * cs_
Definition: spi.h:67
GPIO miso_
Definition: spi.h:61
bool is_busy()
Definition: spi.h:51
volatile bool busy_
Definition: spi.h:68
uint8_t transfer_byte(uint8_t data, GPIO *cs=NULL)
Definition: spi.cpp:160
GPIO mosi_
Definition: spi.h:60
void set_divisor(uint16_t new_divisor)
Definition: spi.cpp:109
uint8_t * in_buffer_ptr_
Definition: spi.h:55
Definition: gpio.h:37
DMA_InitTypeDef DMA_InitStructure_
Definition: spi.h:64
void cb(uint8_t byte)
Definition: ublox.cpp:8
void perform_transfer()
Definition: spi.cpp:221
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:66
void disable(GPIO &cs)
Definition: spi.cpp:155


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:48