Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Set bit in register of sgtl5000 - how?

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    14

    Set bit in register of sgtl5000 - how?

    Hi guys,

    how can I set a bit in a register in the audio library without editing the control_sgtl5000.cpp?

    Have a nice weekend
    Bruno

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,036
    You could just use the Wire library to talk directly to the SGTL5000 chip, if you *really* don't want to do the easiest thing and just edit control_sgtl5000.cpp.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    14
    Hi Paul,
    I have already edited the control_sgtl5000.cpp and set the bit, it works.
    Then I have to make the change with every update of the audio library, because I don't know exactly how it works with I2C.
    But you could also add a method that sets bit 8 in the CHIP_ANA_ADC_CTRL register ;o)

    Greetings
    Bruno

    PS: By the way, you are doing a wonderful job! I love the Teensy 4.x!

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,036
    Quote Originally Posted by DIYLAB View Post
    But you could also add a method that sets bit 8 in the CHIP_ANA_ADC_CTRL register ;o)
    What should that function be named and how should it be documented?

    Please look at the SGTL5000 documentation in the right-side panel of the design tool.

    https://www.pjrc.com/teensy/gui/?inf...ontrolSGTL5000

    If you want to seriously propose an addition to the library, at the very least it needs to have a name and description which fit well into the existing API and documentation. I'm *not* going to just add a "setEightBitsInADCCTRL" function!

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    7,065
    Maybe just make these public:
    Code:
    	unsigned int read(unsigned int reg);
    	bool write(unsigned int reg, unsigned int val);
    .or DIYLAB could write a wrapper (descendant of AudioControlSGTL5000)

  6. #6
    Junior Member
    Join Date
    Jun 2020
    Posts
    14
    Quote Originally Posted by PaulStoffregen View Post
    What should that function be named and how should it be documented?
    Well, one could derive it from the data sheet (page 36)...

    "ADC Volume Range Reduction
    This bit shifts both right and left analog ADC volume range down by 6.0 dB.
    0x0 = No change in ADC range
    0x1 = ADC range reduced by 6.0 dB"

    ...and call the method "VolumeRangeReduction".

    Greetings
    Bruno

  7. #7
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    346
    Quote Originally Posted by Frank B View Post
    Maybe just make these public:
    Code:
    	unsigned int read(unsigned int reg);
    	bool write(unsigned int reg, unsigned int val);

    That indeed would be very usefull for many of us that have been "fiddling" with the SGTL5000 library itself, simply declaring these public allows easy development of additional functions in separate libraries !

    regards
    Cor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •