<commit_before>:mod:`drivers` --- Device drivers
=================================

.. module:: drivers
   :synopsis: Device drivers.

This module contains device drivers.

The following classes are defined:

- :class:`class Pin<.Pin>` -- Digital pins
- :class:`class Exti<.Exti>` -- External interrupts
- :class:`class Adc<.Adc>` -- Analog to digital convertion
- :class:`class Dac<.Dac>` -- Digital to analog convertion
- :class:`class Spi<.Spi>` -- Serial Peripheral Interface
- :class:`class I2CSoft<.I2CSoft>` -- Software I2C
- :class:`class Sd<.Sd>` -- Secure Digital memory
- :class:`class esp_wifi<.esp_wifi>` -- Espressif WiFi

Simba documentation: `drivers`_

----------------------------------------------


.. class:: drivers.Pin(device, mode)

   Create a pin object with given `device` and `mode`. The `device` is
   selected among the pins available in the `board` module. `mode`
   must be either :data:`.INPUT` or :data:`.OUTPUT`.

   .. code-block:: python

      >>> led = Pin(board.PIN_LED, Pin.OUTPUT)
      >>> led.write(1)
      >>> led.toggle()

   Simba documentation: `drivers/pin`_


   .. method:: read()

      Read the current pin value and return it as an integer. Returns
      0 if the pin is low and 1 if the pin is high.


   .. method:: write(value)

      Write the logic level `value` to the pin. `value` must be an
      object that can be converted to an integer. The value is either
      0 or 1, where 0 is low and 1 is high.


   .. method:: toggle()

      Toggle the pin output value (high/low).


   .. method:: set_mode(mode)

      Set the pin mode to given mode `mode`. The mode must be either
      :data:`.INPUT` or :data:`.OUTPUT`.


   .. data:: INPUT

      Input pin mode.


   .. data:: OUTPUT

      Output pin mode.


.. class:: drivers.Exti(device, trigger, event=None, mask=0x1, callback=None)

   Create an object handling interrupts on given `device`. `trigger`
   may be a combination of :data:`.RISING`, :data:`.FALLING` or
   :data:`.BOTH`. When an interrupt occurs given `callback` is called
   from interrupt context and `mask` is written to given event channel
   `event`.

   .. code-block:: python

      >>> event = Event()
      >>> exti = Exti(board.EXTI_D3, Exti.FALLING, event, 0x1)
      >>> exti.start()
      >>> event.read(0x1)        # Wait for an interrupt to occur.
      >>> exti.stop()

   Simba documentation: `drivers/exti`_


   .. method:: start()

      Start the interrupt handler.


   .. method:: stop()

      Stop the interrupt handler.


   .. data:: RISING

      Trigger an interrupt on rising edges.


   .. data:: FALLING

      Trigger an interrupt on falling edges.


   .. data:: BOTH

      Trigger an interrupt on both rising and falling edges.


.. class:: drivers.Adc(device, pin_device, reference, sampling_rate)

   Instansiate an Adc object. `device` is ...

   Here is an example of how to create a ADC driver and convert an
   analog signal level to three digital samples with a sampling rate
   of 1 kHz.

   .. code-block:: python

      >>> a0 = Adc(board.PIN_ADC0, board.PIN_A0, Adc.REFERENCE_VCC, 1000)
      >>> a0.convert(3)
      b'\x01\x02\x03\x04\x05\x06'

   Simba documentation: `drivers/adc`_


   .. method:: convert(number_of_samples)

      Start a synchronous convertion of an analog signal to digital
      samples. This is equivalent to `async_convert()` +
      `async_wait()`, but in a single function call. Returns a bytes
      object where each sample is 2 bytes.


   .. method:: async_convert(number_of_samples)

      Start an asynchronous convertion of analog signal to digital
      samples. Call `async_wait()` to wait for the convertion to
      complete.


   .. method:: async_wait()

      Wait for an asynchronous convertion to complete.
<commit_msg>Documentation.<commit_after>:mod:`drivers` --- Device drivers
=================================

.. module:: drivers
   :synopsis: Device drivers.

This module contains device drivers.

The following classes are defined:

- :class:`class Pin<.Pin>` -- Digital pins
- :class:`class Exti<.Exti>` -- External interrupts
- :class:`class Adc<.Adc>` -- Analog to digital convertion
- :class:`class Dac<.Dac>` -- Digital to analog convertion
- :class:`class Spi<.Spi>` -- Serial Peripheral Interface
- :class:`class I2CSoft<.I2CSoft>` -- Software I2C
- :class:`class Sd<.Sd>` -- Secure Digital memory
- :class:`class esp_wifi<.esp_wifi>` -- Espressif WiFi

Simba documentation: `drivers`_

----------------------------------------------


.. class:: drivers.Pin(device, mode)

   Create a pin object with given `device` and `mode`. The `device` is
   selected among the pins available in the `board` module. `mode`
   must be either :data:`.INPUT` or :data:`.OUTPUT`.

   .. code-block:: python

      >>> led = Pin(board.PIN_LED, Pin.OUTPUT)
      >>> led.write(1)
      >>> led.toggle()

   Simba documentation: `drivers/pin`_


   .. method:: read()

      Read the current pin value and return it as an integer. Returns
      0 if the pin is low and 1 if the pin is high.


   .. method:: write(value)

      Write the logic level `value` to the pin. `value` must be an
      object that can be converted to an integer. The value is either
      0 or 1, where 0 is low and 1 is high.


   .. method:: toggle()

      Toggle the pin output value (high/low).


   .. method:: set_mode(mode)

      Set the pin mode to given mode `mode`. The mode must be either
      :data:`.INPUT` or :data:`.OUTPUT`.


   .. data:: INPUT

      Input pin mode.


   .. data:: OUTPUT

      Output pin mode.


.. class:: drivers.Exti(device, trigger, event=None, mask=0x1, callback=None)

   Create an object handling interrupts on given `device`. `trigger`
   may be a combination of :data:`.RISING`, :data:`.FALLING` or
   :data:`.BOTH`. When an interrupt occurs given `callback` is called
   from interrupt context and `mask` is written to given event channel
   `event`.

   .. code-block:: python

      >>> event = Event()
      >>> exti = Exti(board.EXTI_D3, Exti.FALLING, event, 0x1)
      >>> exti.start()
      >>> event.read(0x1)        # Wait for an interrupt to occur.
      >>> exti.stop()

   Simba documentation: `drivers/exti`_


   .. method:: start()

      Start the interrupt handler.


   .. method:: stop()

      Stop the interrupt handler.


   .. data:: RISING

      Trigger an interrupt on rising edges.


   .. data:: FALLING

      Trigger an interrupt on falling edges.


   .. data:: BOTH

      Trigger an interrupt on both rising and falling edges.


.. class:: drivers.Adc(device, pin_device, reference, sampling_rate)

   Instansiate an Adc object with given `device` and `pin_device`
   devices. `reference` is the voltage reference and `sampling_rate`
   is the sampling frequency.

   Here is an example of how to create a ADC driver object and convert
   an analog signal level to three digital samples with a sampling
   rate of 1 kHz.

   .. code-block:: python

      >>> a0 = Adc(board.PIN_ADC0, board.PIN_A0, Adc.REFERENCE_VCC, 1000)
      >>> a0.convert(3)
      b'\x01\x02\x03\x04\x05\x06'

   The equivalent asynchronous example.

   .. code-block:: python

      >>> a0 = Adc(board.PIN_ADC0, board.PIN_A0, Adc.REFERENCE_VCC, 1000)
      >>> a0.async_convert(3)
      >>> a0.async_wait()
      b'\x01\x02\x03\x04\x05\x06'

   Simba documentation: `drivers/adc`_


   .. method:: convert(number_of_samples)

      Start a synchronous convertion of an analog signal to digital
      samples. This is equivalent to :meth:`.async_convert()` +
      :meth:`.async_wait()`, but in a single function call. Returns a
      bytes object where each sample is 2 bytes.


   .. method:: async_convert(number_of_samples)

      Start an asynchronous convertion of analog signal to digital
      samples. Call :meth:`.async_wait()` to wait for the convertion
      to complete.


   .. method:: async_wait()

      Wait for an asynchronous convertion started with
      :meth:`.async_convert()` to complete. Returns a bytes object
      where each sample is 2 bytes.

{'fraction_non_alphanumeric': 0.1342248637939574, 'fraction_numerical': 0.012753838533927687, 'mean_word_length': 2.6481481481481484, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5405938', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2354, 'n_words': 883}