Skip to content

Commit f8012f6

Browse files
SPRESENSEShunichi-K
authored andcommitted
Merge snapshot for v1.1.2 (#12)
Commits: 12f3954 Support SPI 16bit buffer transfer e46ff4c Fix the way of the alloc/free output variables 30ca3f8 Fix doxygen comments 60aceda Prevent NULL reference by box brackets e847708 Fix unexpected free memory
1 parent e4877c5 commit f8012f6

File tree

4 files changed

+87
-16
lines changed

4 files changed

+87
-16
lines changed

Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/libraries/DNNRT/DNNRT.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ DNNRT::begin(File& nnbfile)
9494
// Allocate input and output data array from network model
9595

9696
_input = (void **)malloc(sizeof(void *) * _nr_inputs);
97-
_output = (DNNVariable *)malloc(sizeof(DNNVariable) * _nr_outputs);
97+
_output = new DNNVariable[_nr_outputs];
9898

9999
return 0;
100100
}
@@ -119,14 +119,14 @@ DNNRT::end()
119119
}
120120
if (_output)
121121
{
122-
free(_output);
122+
delete[] _output;
123123
}
124124

125125
return 0;
126126
}
127127

128128
int
129-
DNNRT::inputVariable(DNNVariable var, unsigned int index)
129+
DNNRT::inputVariable(DNNVariable &var, unsigned int index)
130130
{
131131
if (index >= (unsigned int)_nr_inputs)
132132
{

Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/libraries/DNNRT/DNNRT.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ class DNNRT {
4545

4646
/**
4747
* Initialize runtime object from .nnb file
48-
*
49-
* User must be generate a network model data file (.nnb) by NNabla before
50-
* run this library.
51-
*
52-
* About NNabla:
53-
* https://nnabla.readthedocs.io/en/latest/python/index.html
54-
* About NNB file:
55-
* https://nnabla.readthedocs.io/en/latest/python/file_format_converter/file_format_converter.html
56-
*
57-
* @param nnbfile nnb network model database file
48+
*
49+
* User must be generate a network model data file (.nnb) by Neural Network
50+
* Console (NNC) before use this library.
51+
*
52+
* About Neural Network Console:
53+
* https://dl.sony.com/
54+
*
55+
* @param nnbfile nnb network model binary file
5856
* @return 0 on success, otherwise error.
5957
*/
6058
int begin(SDHCILib::File &nnbfile);
@@ -74,7 +72,7 @@ class DNNRT {
7472
* @return 0 on success, otherwise error.
7573
* @note Number of input data is depends on the network model.
7674
*/
77-
int inputVariable(DNNVariable var, unsigned int index);
75+
int inputVariable(DNNVariable &var, unsigned int index);
7876

7977
/**
8078
* Get output data at index
@@ -170,7 +168,6 @@ class DNNVariable {
170168
friend class DNNRT;
171169

172170
public:
173-
DNNVariable();
174171
DNNVariable(unsigned int size);
175172
~DNNVariable();
176173

@@ -207,6 +204,7 @@ class DNNVariable {
207204
int maxIndex();
208205

209206
private:
207+
DNNVariable();
210208
float *_data;
211209
unsigned int _size;
212210
bool _allocated;

Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/libraries/SPI/SPI.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,46 @@ void SPIClass::transfer(void *buf, size_t count)
308308
if (do_free)
309309
free(recv);
310310
}
311+
312+
void SPIClass::transfer16(void *buf, size_t count)
313+
{
314+
bool do_free = false;
315+
uint16_t *recv = NULL;
316+
if (ref_count == 0 || !buf || count == 0)
317+
return;
318+
319+
if ((count * sizeof(uint16_t)) > 256) {
320+
recv = (uint16_t*)malloc(count * sizeof(uint16_t));
321+
do_free = true;
322+
if (!recv)
323+
return;
324+
}
325+
else {
326+
recv = (uint16_t*)__builtin_alloca(count * sizeof(uint16_t));
327+
}
328+
329+
SPI_SETBITS(spi_dev, 16);
330+
SPI_EXCHANGE(spi_dev, buf, recv, count);
331+
332+
memcpy(buf, recv, count * sizeof(uint16_t));
333+
if (do_free)
334+
free(recv);
335+
}
336+
337+
void SPIClass::send(void *buf, size_t count)
338+
{
339+
if (ref_count == 0 || !buf || count == 0)
340+
return;
341+
342+
SPI_SETBITS(spi_dev, 8);
343+
SPI_EXCHANGE(spi_dev, buf, NULL, count);
344+
}
345+
346+
void SPIClass::send16(void *buf, size_t count)
347+
{
348+
if (ref_count == 0 || !buf || count == 0)
349+
return;
350+
351+
SPI_SETBITS(spi_dev, 16);
352+
SPI_EXCHANGE(spi_dev, buf, NULL, count);
353+
}

Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/libraries/SPI/SPI.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,41 @@ class SPIClass {
232232
/**
233233
* @brief Write data to the SPI bus and also receive data
234234
*
235-
* @param [in] data Buffer to send
235+
* @param [in,out] buf Buffer to send and receive
236236
* @param [in] count The number of bytes to transmit
237237
*/
238238
void transfer(void *buf, size_t count);
239239

240+
/**
241+
* @brief Write 16-bit data to the SPI bus and also receive data
242+
*
243+
* @param [in,out] buf Buffer to send and receive
244+
* @param [in] count The number of 16-bit data to transmit
245+
*/
246+
void transfer16(void *buf, size_t count);
247+
248+
/**
249+
* @brief Write buffer to the SPI bus (only write transfer)
250+
*
251+
* @note This supports only Tx transfer. There is no Rx received data.
252+
* It assumes that this is used for LCD display.
253+
*
254+
* @param [in] buf Buffer to send
255+
* @param [in] count The number of bytes to transmit
256+
*/
257+
void send(void *buf, size_t count);
258+
259+
/**
260+
* @brief Write 16-bit buffer the SPI bus (only write transfer)
261+
*
262+
* @note This supports only Tx transfer. There is no Rx received data.
263+
* It assumes that this is used for LCD display.
264+
*
265+
* @param [in] buf Buffer to send
266+
* @param [in] count The number of 16-bit data to transmit
267+
*/
268+
void send16(void *buf, size_t count);
269+
240270
private:
241271
int spi_port; /**< SPI port number */
242272
uint8_t ref_count; /**< Count of SPI references */

0 commit comments

Comments
 (0)