@@ -809,6 +809,23 @@ STATIC mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) {
809
809
}
810
810
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (rp2_state_machine_tx_fifo_obj , rp2_state_machine_tx_fifo );
811
811
812
+ // Buffer protocol implementation for StateMachine
813
+ // The buffer represents one of the FIFO ports of the state machine. Note that a different
814
+ // pointer is returned depending on if this is for reading or writing.
815
+ STATIC mp_int_t rp2_state_machine_get_buffer (mp_obj_t o_in , mp_buffer_info_t * bufinfo , mp_uint_t flags ) {
816
+ rp2_state_machine_obj_t * self = MP_OBJ_TO_PTR (o_in );
817
+
818
+ bufinfo -> len = 4 ;
819
+ bufinfo -> typecode = 'I' ;
820
+
821
+ if (flags & MP_BUFFER_WRITE ) {
822
+ bufinfo -> buf = (void * )& self -> pio -> txf [self -> sm ];
823
+ } else {
824
+ bufinfo -> buf = (void * )& self -> pio -> rxf [self -> sm ];
825
+ }
826
+ return 0 ;
827
+ }
828
+
812
829
// StateMachine.irq(handler=None, trigger=0|1, hard=False)
813
830
STATIC mp_obj_t rp2_state_machine_irq (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
814
831
enum { ARG_handler , ARG_trigger , ARG_hard };
@@ -884,6 +901,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
884
901
MP_TYPE_FLAG_NONE ,
885
902
make_new , rp2_state_machine_make_new ,
886
903
print , rp2_state_machine_print ,
904
+ buffer , rp2_state_machine_get_buffer ,
887
905
locals_dict , & rp2_state_machine_locals_dict
888
906
);
889
907
0 commit comments