@@ -187,11 +187,33 @@ enum {
187
187
ARG_INIT_firstbit
188
188
};
189
189
190
+ static inline uint32_t machine_hard_spi_get_baudrate (const machine_hard_spi_obj_t * self ) {
191
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_125K == (2 << 24 ));
192
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_250K == (4 << 24 ));
193
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_500K == (8 << 24 ));
194
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_1M == (16 << 24 ));
195
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_2M == (32 << 24 ));
196
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_4M == (64 << 24 ));
197
+ MP_STATIC_ASSERT (NRF_SPI_FREQ_8M == (128 << 24 ));
198
+ #if defined(NRF52840_XXAA ) && NRFX_SPIM_ENABLED
199
+ if (self -> p_config -> frequency == NRF_SPIM_FREQ_16M ) {
200
+ return 16000000 ;
201
+ }
202
+ if (self -> p_config -> frequency == NRF_SPIM_FREQ_32M ) {
203
+ return 32000000 ;
204
+ }
205
+ #endif
206
+ return 125000 * (self -> p_config -> frequency >> 25 );
207
+ }
208
+
190
209
static void machine_hard_spi_init_helper (const machine_hard_spi_obj_t * self , mp_arg_val_t * args );
191
210
192
211
static void machine_hard_spi_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
193
212
machine_hard_spi_obj_t * self = self_in ;
194
- mp_printf (print , "SPI(%u)" , self -> p_spi -> drv_inst_idx );
213
+ unsigned int polarity = self -> p_config -> mode == NRF_SPI_MODE_0 || self -> p_config -> mode == NRF_SPI_MODE_1 ? 0 : 1 ;
214
+ unsigned int phase = self -> p_config -> mode == NRF_SPI_MODE_0 || self -> p_config -> mode == NRF_SPI_MODE_2 ? 0 : 1 ;
215
+ mp_printf (print , "SPI(%u, baudrate=%u, polarity=%u, phase=%u)" ,
216
+ self -> p_spi -> drv_inst_idx , machine_hard_spi_get_baudrate (self ), polarity , phase );
195
217
}
196
218
197
219
static mp_obj_t machine_hard_spi_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
0 commit comments