Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
/* Copyright (c) 2015-2017 Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright notice, this
 *      list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *
 *   3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *      contributors may be used to endorse or promote products derived from
 *      this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/**
 * @ingroup nrf_twis
 * @defgroup nrf_twis_hal TWIS HAL
 * @{
 *
 * @brief @tagAPI52 Hardware access layer for Two Wire Interface Slave with EasyDMA
 * (TWIS) peripheral.
 */
#ifndef NRF_TWIS_H__
#define NRF_TWIS_H__

#include "nrf.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief TWIS tasks
 */
typedef enum
{
    /*lint -save -e30*/
    NRF_TWIS_TASK_STOP      = offsetof(NRF_TWIS_Type, TASKS_STOP),      /**< Stop TWIS transaction */
    NRF_TWIS_TASK_SUSPEND   = offsetof(NRF_TWIS_Type, TASKS_SUSPEND),   /**< Suspend TWIS transaction */
    NRF_TWIS_TASK_RESUME    = offsetof(NRF_TWIS_Type, TASKS_RESUME),    /**< Resume TWIS transaction */
    NRF_TWIS_TASK_PREPARERX = offsetof(NRF_TWIS_Type, TASKS_PREPARERX), /**< Prepare the TWIS slave to respond to a write command */
    NRF_TWIS_TASK_PREPARETX = offsetof(NRF_TWIS_Type, TASKS_PREPARETX)  /**< Prepare the TWIS slave to respond to a read command */
    /*lint -restore*/
} nrf_twis_task_t;

/**
 * @brief TWIS events
 */
typedef enum
{
    /*lint -save -e30*/
    NRF_TWIS_EVENT_STOPPED   = offsetof(NRF_TWIS_Type, EVENTS_STOPPED),   /**< TWIS stopped */
    NRF_TWIS_EVENT_ERROR     = offsetof(NRF_TWIS_Type, EVENTS_ERROR),     /**< TWIS error */
    NRF_TWIS_EVENT_RXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_RXSTARTED), /**< Receive sequence started */
    NRF_TWIS_EVENT_TXSTARTED = offsetof(NRF_TWIS_Type, EVENTS_TXSTARTED), /**< Transmit sequence started */
    NRF_TWIS_EVENT_WRITE     = offsetof(NRF_TWIS_Type, EVENTS_WRITE),     /**< Write command received */
    NRF_TWIS_EVENT_READ      = offsetof(NRF_TWIS_Type, EVENTS_READ)       /**< Read command received */
    /*lint -restore*/
} nrf_twis_event_t;

/**
 * @brief TWIS shortcuts
 */
typedef enum
{
    NRF_TWIS_SHORT_WRITE_SUSPEND_MASK   = TWIS_SHORTS_WRITE_SUSPEND_Msk,   /**< Shortcut between WRITE event and SUSPEND task */
    NRF_TWIS_SHORT_READ_SUSPEND_MASK    = TWIS_SHORTS_READ_SUSPEND_Msk,    /**< Shortcut between READ event and SUSPEND task */
} nrf_twis_short_mask_t;

/**
 * @brief TWIS interrupts
 */
typedef enum
{
    NRF_TWIS_INT_STOPPED_MASK   = TWIS_INTEN_STOPPED_Msk,   /**< Interrupt on STOPPED event */
    NRF_TWIS_INT_ERROR_MASK     = TWIS_INTEN_ERROR_Msk,     /**< Interrupt on ERROR event */
    NRF_TWIS_INT_RXSTARTED_MASK = TWIS_INTEN_RXSTARTED_Msk, /**< Interrupt on RXSTARTED event */
    NRF_TWIS_INT_TXSTARTED_MASK = TWIS_INTEN_TXSTARTED_Msk, /**< Interrupt on TXSTARTED event */
    NRF_TWIS_INT_WRITE_MASK     = TWIS_INTEN_WRITE_Msk,     /**< Interrupt on WRITE event */
    NRF_TWIS_INT_READ_MASK      = TWIS_INTEN_READ_Msk,      /**< Interrupt on READ event */
} nrf_twis_int_mask_t;

/**
 * @brief TWIS error source
 */
typedef enum
{
    NRF_TWIS_ERROR_OVERFLOW  = TWIS_ERRORSRC_OVERFLOW_Msk, /**< RX buffer overflow detected, and prevented */
    NRF_TWIS_ERROR_DATA_NACK = TWIS_ERRORSRC_DNACK_Msk,    /**< NACK sent after receiving a data byte */
    NRF_TWIS_ERROR_OVERREAD  = TWIS_ERRORSRC_OVERREAD_Msk  /**< TX buffer over-read detected, and prevented */
} nrf_twis_error_t;

/**
 * @brief TWIS address matching configuration
 */
typedef enum
{
    NRF_TWIS_CONFIG_ADDRESS0_MASK  = TWIS_CONFIG_ADDRESS0_Msk, /**< Enable or disable address matching on ADDRESS[0] */
    NRF_TWIS_CONFIG_ADDRESS1_MASK  = TWIS_CONFIG_ADDRESS1_Msk, /**< Enable or disable address matching on ADDRESS[1] */
    NRF_TWIS_CONFIG_ADDRESS01_MASK = TWIS_CONFIG_ADDRESS0_Msk | TWIS_CONFIG_ADDRESS1_Msk /**< Enable both address matching */
} nrf_twis_config_addr_mask_t;

/**
 * @brief Variable type to hold amount of data for EasyDMA
 *
 * Variable of the minimum size that can hold the amount of data to transfer.
 *
 * @note
 * Defined to make it simple to change if EasyDMA would be updated to support more data in
 * the future devices to.
 */
typedef uint8_t nrf_twis_amount_t;

/**
 * @brief Smallest variable type to hold TWI address
 *
 * Variable of the minimum size that can hold single TWI address.
 *
 * @note
 * Defined to make it simple to change if new TWI would support for example
 * 10 bit addressing mode.
 */
typedef uint8_t nrf_twis_address_t;


/**
 * @brief Function for activating a specific TWIS task.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     task   Task.
 */
__STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type * const p_reg, nrf_twis_task_t task);

/**
 * @brief Function for returning the address of a specific TWIS task register.
 *
 * @param[in]  p_reg Pointer to the peripheral registers structure.
 * @param      task   Task.
 *
 * @return Task address.
 */
__STATIC_INLINE uint32_t nrf_twis_task_address_get(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_task_t      task);

/**
 * @brief Function for clearing a specific event.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     event  Event.
 */
__STATIC_INLINE void nrf_twis_event_clear(
        NRF_TWIS_Type     * const p_reg,
        nrf_twis_event_t   event);
/**
 * @brief Function for returning the state of a specific event.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     event  Event.
 *
 * @retval true If the event is set.
 * @retval false If the event is not set.
 */
__STATIC_INLINE bool nrf_twis_event_check(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_event_t     event);


/**
 * @brief Function for getting and clearing the state of specific event
 *
 * This function checks the state of the event and clears it.
 * @param[in,out] p_reg Pointer to the peripheral registers structure.
 * @param         event Event.
 *
 * @retval true If the event was set.
 * @retval false If the event was not set.
 */
__STATIC_INLINE bool nrf_twis_event_get_and_clear(
        NRF_TWIS_Type    * const p_reg,
        nrf_twis_event_t   event);


/**
 * @brief Function for returning the address of a specific TWIS event register.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     event  Event.
 *
 * @return Address.
 */
__STATIC_INLINE uint32_t nrf_twis_event_address_get(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_event_t     event);

/**
 * @brief Function for setting a shortcut.
 *
 * @param[in] p_reg     Pointer to the peripheral registers structure.
 * @param     short_mask Shortcuts mask.
 */
__STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type * const p_reg, uint32_t short_mask);

/**
 * @brief Function for clearing shortcuts.
 *
 * @param[in] p_reg     Pointer to the peripheral registers structure.
 * @param     short_mask Shortcuts mask.
 */
__STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type * const p_reg, uint32_t short_mask);

/**
 * @brief Get the shorts mask
 *
 * Function returns shorts register.
 * @param[in] p_reg     Pointer to the peripheral registers structure.
 * @return Flags of currently enabled shortcuts
 */
__STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type * const p_reg);

/**
 * @brief Function for enabling selected interrupts.
 *
 * @param[in] p_reg   Pointer to the peripheral registers structure.
 * @param     int_mask Interrupts mask.
 */
__STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type * const p_reg, uint32_t int_mask);

/**
 * @brief Function for retrieving the state of selected interrupts.
 *
 * @param[in] p_reg   Pointer to the peripheral registers structure.
 * @param     int_mask Interrupts mask.
 *
 * @retval true If any of selected interrupts is enabled.
 * @retval false If none of selected interrupts is enabled.
 */
__STATIC_INLINE bool nrf_twis_int_enable_check(NRF_TWIS_Type const * const p_reg, uint32_t int_mask);

/**
 * @brief Function for disabling selected interrupts.
 *
 * @param[in] p_reg   Pointer to the peripheral registers structure.
 * @param     int_mask Interrupts mask.
 */
__STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t int_mask);

/**
 * @brief Function for retrieving and clearing the TWIS error source.
 *
 * @attention Error sources are cleared after read.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @return Error source mask with values from @ref nrf_twis_error_t.
 */
__STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * const p_reg);

/**
 * @brief Get information which of addresses matched
 *
 * Function returns index in the address table
 * that points to the address that already matched.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @return Index of matched address
 */
__STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg);

/**
 * @brief Function for enabling TWIS.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 */
__STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type * const p_reg);

/**
 * @brief Function for disabling TWIS.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 */
__STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type * const p_reg);

/**
 * @brief Function for configuring TWIS pins.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param scl SCL pin number.
 * @param sda SDA pin number.
 */
__STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type * const p_reg, uint32_t scl, uint32_t sda);

/**
 * @brief Function for setting the receive buffer.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     p_buf  Pointer to the buffer for received data.
 * @param     length Maximum number of data bytes to receive.
 */
__STATIC_INLINE void nrf_twis_rx_buffer_set(
        NRF_TWIS_Type     * const p_reg,
        uint8_t           * p_buf,
        nrf_twis_amount_t   length);

/**
 * @brief Function that prepares TWIS for receiving
 *
 * This function sets receive buffer and then sets NRF_TWIS_TASK_PREPARERX task.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     p_buf  Pointer to the buffer for received data.
 * @param     length Maximum number of data bytes to receive.
 */
__STATIC_INLINE void nrf_twis_rx_prepare(
        NRF_TWIS_Type     * const p_reg,
        uint8_t           * p_buf,
        nrf_twis_amount_t   length);

/**
 * @brief Function for getting number of bytes received in the last transaction.
 *
 * @param[in] p_reg TWIS instance.
 * @return Amount of bytes received.
 * */
__STATIC_INLINE nrf_twis_amount_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * const p_reg);

/**
 * @brief Function for setting the transmit buffer.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     p_buf  Pointer to the buffer with data to send.
 * @param     length Maximum number of data bytes to transmit.
 */
__STATIC_INLINE void nrf_twis_tx_buffer_set(
        NRF_TWIS_Type     * const p_reg,
        uint8_t const     * p_buf,
        nrf_twis_amount_t   length);

/**
 * @brief Function that prepares TWIS for transmitting
 *
 * This function sets transmit buffer and then sets NRF_TWIS_TASK_PREPARETX task.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     p_buf  Pointer to the buffer with data to send.
 * @param     length Maximum number of data bytes to transmit.
 */
__STATIC_INLINE void nrf_twis_tx_prepare(
        NRF_TWIS_Type     * const p_reg,
        uint8_t const     * p_buf,
        nrf_twis_amount_t   length);

/**
 * @brief Function for getting number of bytes transmitted in the last transaction.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @return Amount of bytes transmitted.
 */
__STATIC_INLINE nrf_twis_amount_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * const p_reg);

/**
 * @brief Function for setting slave address
 *
 * Function sets the selected address for this TWI interface.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param     n Index of address to set
 * @param     addr Addres to set
 * @sa nrf_twis_config_address_set
 * @sa nrf_twis_config_address_get
 */
__STATIC_INLINE void nrf_twis_address_set(
        NRF_TWIS_Type      * const p_reg,
        uint_fast8_t         n,
        nrf_twis_address_t   addr);

/**
 * @brief Function for retrieving configured slave address
 *
 * Function gets the selected address for this TWI interface.
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @param n   Index of address to get
 */
__STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(
        NRF_TWIS_Type const * const p_reg,
        uint_fast8_t          n);

/**
 * @brief Function for setting the device address configuration.
 *
 * @param[in] p_reg    Pointer to the peripheral registers structure.
 * @param     addr_mask Mask of address indexes of what device should answer to.
 *
 * @sa nrf_twis_address_set
 */
__STATIC_INLINE void nrf_twis_config_address_set(
        NRF_TWIS_Type              * const p_reg,
        nrf_twis_config_addr_mask_t        addr_mask);

/**
 * @brief Function for retrieving the device address configuration.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 *
 * @return Mask of address indexes of what device should answer to.
 */
__STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get(
        NRF_TWIS_Type const * const p_reg);

/**
 * @brief Function for setting the over-read character.
 *
 * @param[in] p_reg    Pointer to the peripheral registers structure.
 * @param[in] orc       Over-read character. Character clocked out in case of
 *                      over-read of the TXD buffer.
 */
__STATIC_INLINE void nrf_twis_orc_set(
        NRF_TWIS_Type * const p_reg,
        uint8_t         orc);

/**
 * @brief Function for setting the over-read character.
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 *
 * @return Over-read character configured for selected instance.
 */
__STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * const p_reg);


/** @} */ /*  End of nrf_twis_hal */

#ifndef SUPPRESS_INLINE_IMPLEMENTATION

/* ------------------------------------------------------------------------------------------------
 *  Internal functions
 */

/**
 * @internal
 * @brief Internal function for getting task/event register address
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @oaram     offset Offset of the register from the instance beginning
 *
 * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
 * @return Pointer to the register
 */
__STATIC_INLINE volatile uint32_t* nrf_twis_getRegPtr(NRF_TWIS_Type * const p_reg, uint32_t offset)
{
    return (volatile uint32_t*)((uint8_t *)p_reg + (uint32_t)offset);
}

/**
 * @internal
 * @brief Internal function for getting task/event register address - constant version
 *
 * @param[in] p_reg Pointer to the peripheral registers structure.
 * @oaram     offset Offset of the register from the instance beginning
 *
 * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
 * @return Pointer to the register
 */
__STATIC_INLINE volatile const uint32_t* nrf_twis_getRegPtr_c(NRF_TWIS_Type const * const p_reg, uint32_t offset)
{
    return (volatile const uint32_t*)((uint8_t *)p_reg + (uint32_t)offset);
}


/* ------------------------------------------------------------------------------------------------
 *  Interface functions definitions
 */


void nrf_twis_task_trigger(NRF_TWIS_Type * const p_reg, nrf_twis_task_t task)
{
    *(nrf_twis_getRegPtr(p_reg, (uint32_t)task)) = 1UL;
}

uint32_t nrf_twis_task_address_get(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_task_t       task)
{
    return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)task);
}

void nrf_twis_event_clear(
        NRF_TWIS_Type     * const p_reg,
        nrf_twis_event_t    event)
{
    *(nrf_twis_getRegPtr(p_reg, (uint32_t)event)) = 0UL;
#if __CORTEX_M == 0x04
    volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
    (void)dummy;
#endif
}

bool nrf_twis_event_check(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_event_t      event)
{
    return (bool)*nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
}

bool nrf_twis_event_get_and_clear(
        NRF_TWIS_Type    * const p_reg,
        nrf_twis_event_t   event)
{
    bool ret = nrf_twis_event_check(p_reg, event);
    if (ret)
    {
        nrf_twis_event_clear(p_reg, event);
    }
    return ret;
}

uint32_t nrf_twis_event_address_get(
        NRF_TWIS_Type const * const p_reg,
        nrf_twis_event_t      event)
{
    return (uint32_t)nrf_twis_getRegPtr_c(p_reg, (uint32_t)event);
}

void nrf_twis_shorts_enable(NRF_TWIS_Type * const p_reg, uint32_t short_mask)
{
    p_reg->SHORTS |= short_mask;
}

void nrf_twis_shorts_disable(NRF_TWIS_Type * const p_reg, uint32_t short_mask)
{
    if (~0U == short_mask)
    {
        /* Optimized version for "disable all" */
        p_reg->SHORTS = 0;
    }
    else
    {
        p_reg->SHORTS &= ~short_mask;
    }
}

uint32_t nrf_twis_shorts_get(NRF_TWIS_Type * const p_reg)
{
    return p_reg->SHORTS;
}

void nrf_twis_int_enable(NRF_TWIS_Type * const p_reg, uint32_t int_mask)
{
    p_reg->INTENSET = int_mask;
}

bool nrf_twis_int_enable_check(NRF_TWIS_Type const * const p_reg, uint32_t int_mask)
{
    return (bool)(p_reg->INTENSET & int_mask);
}

void nrf_twis_int_disable(NRF_TWIS_Type * const p_reg, uint32_t int_mask)
{
    p_reg->INTENCLR = int_mask;
}

uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type * const p_reg)
{
    uint32_t ret = p_reg->ERRORSRC;
    p_reg->ERRORSRC = ret;
    return ret;
}

uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const * p_reg)
{
    return (uint_fast8_t)p_reg->MATCH;
}

void nrf_twis_enable(NRF_TWIS_Type * const p_reg)
{
    p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos);
}

void nrf_twis_disable(NRF_TWIS_Type * const p_reg)
{
    p_reg->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos);
}

void nrf_twis_pins_set(NRF_TWIS_Type * const p_reg, uint32_t scl, uint32_t sda)
{
    p_reg->PSEL.SCL = scl;
    p_reg->PSEL.SDA = sda;
}

void nrf_twis_rx_buffer_set(
        NRF_TWIS_Type     * const p_reg,
        uint8_t           * p_buf,
        nrf_twis_amount_t   length)
{
    p_reg->RXD.PTR    = (uint32_t)p_buf;
    p_reg->RXD.MAXCNT = length;
}

__STATIC_INLINE void nrf_twis_rx_prepare(
        NRF_TWIS_Type     * const p_reg,
        uint8_t           * p_buf,
        nrf_twis_amount_t   length)
{
    nrf_twis_rx_buffer_set(p_reg, p_buf, length);
    nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARERX);
}

nrf_twis_amount_t nrf_twis_rx_amount_get(NRF_TWIS_Type const * const p_reg)
{
    return (nrf_twis_amount_t)p_reg->RXD.AMOUNT;
}

void nrf_twis_tx_buffer_set(
        NRF_TWIS_Type     * const p_reg,
        uint8_t const     * p_buf,
        nrf_twis_amount_t   length)
{
    p_reg->TXD.PTR    = (uint32_t)p_buf;
    p_reg->TXD.MAXCNT = length;
}

__STATIC_INLINE void nrf_twis_tx_prepare(
        NRF_TWIS_Type     * const p_reg,
        uint8_t const     * p_buf,
        nrf_twis_amount_t   length)
{
    nrf_twis_tx_buffer_set(p_reg, p_buf, length);
    nrf_twis_task_trigger(p_reg, NRF_TWIS_TASK_PREPARETX);
}

nrf_twis_amount_t nrf_twis_tx_amount_get(NRF_TWIS_Type const * const p_reg)
{
    return (nrf_twis_amount_t)p_reg->TXD.AMOUNT;
}

void nrf_twis_address_set(
        NRF_TWIS_Type      * const p_reg,
        uint_fast8_t         n,
        nrf_twis_address_t   addr)
{
    p_reg->ADDRESS[n] = addr;
}

nrf_twis_address_t nrf_twis_address_get(
        NRF_TWIS_Type const * const p_reg,
        uint_fast8_t          n)
{
    return (nrf_twis_address_t)p_reg->ADDRESS[n];
}
void nrf_twis_config_address_set(
        NRF_TWIS_Type              * const p_reg,
        nrf_twis_config_addr_mask_t        addr_mask)
{
    /* This is the only configuration in TWIS - just write it without masking */
    p_reg->CONFIG = addr_mask;
}

nrf_twis_config_addr_mask_t nrf_twis_config_address_get(NRF_TWIS_Type const * const p_reg)
{
    return (nrf_twis_config_addr_mask_t)(p_reg->CONFIG & TWIS_ADDRESS_ADDRESS_Msk);
}

void nrf_twis_orc_set(
        NRF_TWIS_Type * const p_reg,
        uint8_t         orc)
{
    p_reg->ORC = orc;
}

uint8_t nrf_twis_orc_get(NRF_TWIS_Type const * const p_reg)
{
    return (uint8_t)p_reg->ORC;
}

#endif /* SUPPRESS_INLINE_IMPLEMENTATION */


#ifdef __cplusplus
}
#endif

#endif /* NRF_TWIS_H__ */