@@ -125,53 +125,23 @@ static int spi_mcux_transfer_next_packet(const struct device *dev)
125
125
struct spi_mcux_data * data = dev -> data ;
126
126
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
127
127
struct spi_context * ctx = & data -> ctx ;
128
+ size_t max_chunk = spi_context_max_continuous_chunk (ctx );
128
129
lpspi_transfer_t transfer ;
129
130
status_t status ;
130
131
131
- if ((ctx -> tx_len == 0 ) && (ctx -> rx_len == 0 )) {
132
- /* nothing left to rx or tx, we're done! */
133
- spi_context_cs_control (& data -> ctx , false);
134
- spi_context_complete (& data -> ctx , dev , 0 );
132
+ if (max_chunk == 0 ) {
133
+ spi_context_cs_control (ctx , false);
134
+ spi_context_complete (ctx , dev , 0 );
135
135
return 0 ;
136
136
}
137
137
138
+ data -> transfer_len = max_chunk ;
139
+
138
140
transfer .configFlags =
139
141
kLPSPI_MasterPcsContinuous | (ctx -> config -> slave << LPSPI_MASTER_PCS_SHIFT );
140
-
141
- if (ctx -> tx_len == 0 ) {
142
- /* rx only, nothing to tx */
143
- transfer .txData = NULL ;
144
- transfer .rxData = ctx -> rx_buf ;
145
- transfer .dataSize = ctx -> rx_len ;
146
- } else if (ctx -> rx_len == 0 ) {
147
- /* tx only, nothing to rx */
148
- transfer .txData = (uint8_t * )ctx -> tx_buf ;
149
- transfer .rxData = NULL ;
150
- transfer .dataSize = ctx -> tx_len ;
151
- } else if (ctx -> tx_len == ctx -> rx_len ) {
152
- /* rx and tx are the same length */
153
- transfer .txData = (uint8_t * )ctx -> tx_buf ;
154
- transfer .rxData = ctx -> rx_buf ;
155
- transfer .dataSize = ctx -> tx_len ;
156
- } else if (ctx -> tx_len > ctx -> rx_len ) {
157
- /* Break up the tx into multiple transfers so we don't have to
158
- * rx into a longer intermediate buffer. Leave chip select
159
- * active between transfers.
160
- */
161
- transfer .txData = (uint8_t * )ctx -> tx_buf ;
162
- transfer .rxData = ctx -> rx_buf ;
163
- transfer .dataSize = ctx -> rx_len ;
164
- } else {
165
- /* Break up the rx into multiple transfers so we don't have to
166
- * tx from a longer intermediate buffer. Leave chip select
167
- * active between transfers.
168
- */
169
- transfer .txData = (uint8_t * )ctx -> tx_buf ;
170
- transfer .rxData = ctx -> rx_buf ;
171
- transfer .dataSize = ctx -> tx_len ;
172
- }
173
-
174
- data -> transfer_len = transfer .dataSize ;
142
+ transfer .txData = (ctx -> tx_len == 0 ? NULL : ctx -> tx_buf );
143
+ transfer .rxData = (ctx -> rx_len == 0 ? NULL : ctx -> rx_buf );
144
+ transfer .dataSize = max_chunk ;
175
145
176
146
status = LPSPI_MasterTransferNonBlocking (base , & data -> handle , & transfer );
177
147
if (status != kStatus_Success ) {
0 commit comments