2929//| clock: microcontroller.Pin,
3030//| mosi: microcontroller.Pin,
3131//| cs: microcontroller.Pin,
32+ //| *,
33+ //| gain: int = 1,
3234//| ) -> None:
3335//| """Create a DACOut object associated with the given SPI pins.
3436//|
3537//| :param ~microcontroller.Pin clock: The SPI clock (SCK) pin
3638//| :param ~microcontroller.Pin mosi: The SPI data (SDI/MOSI) pin
3739//| :param ~microcontroller.Pin cs: The chip select (CS) pin
40+ //| :param int gain: DAC output gain, 1 for 1x (0-2.048V) or 2 for 2x (0-4.096V). Default 1.
3841//|
3942//| Simple 8ksps 440 Hz sine wave::
4043//|
7275//| ...
7376//|
7477static mp_obj_t mtm_hardware_dacout_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
75- enum { ARG_clock , ARG_mosi , ARG_cs };
78+ enum { ARG_clock , ARG_mosi , ARG_cs , ARG_gain };
7679 static const mp_arg_t allowed_args [] = {
7780 { MP_QSTR_clock , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
7881 { MP_QSTR_mosi , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
7982 { MP_QSTR_cs , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
83+ { MP_QSTR_gain , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 1 } },
8084 };
8185 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
8286 mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -85,8 +89,13 @@ static mp_obj_t mtm_hardware_dacout_make_new(const mp_obj_type_t *type, size_t n
8589 const mcu_pin_obj_t * mosi = validate_obj_is_free_pin (args [ARG_mosi ].u_obj , MP_QSTR_mosi );
8690 const mcu_pin_obj_t * cs = validate_obj_is_free_pin (args [ARG_cs ].u_obj , MP_QSTR_cs );
8791
92+ mp_int_t gain = args [ARG_gain ].u_int ;
93+ if (gain != 1 && gain != 2 ) {
94+ mp_raise_ValueError (MP_COMPRESSED_ROM_TEXT ("gain must be 1 or 2" ));
95+ }
96+
8897 mtm_hardware_dacout_obj_t * self = mp_obj_malloc_with_finaliser (mtm_hardware_dacout_obj_t , & mtm_hardware_dacout_type );
89- common_hal_mtm_hardware_dacout_construct (self , clock , mosi , cs );
98+ common_hal_mtm_hardware_dacout_construct (self , clock , mosi , cs , ( uint8_t ) gain );
9099
91100 return MP_OBJ_FROM_PTR (self );
92101}
0 commit comments