qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
18.19k stars 39.18k forks source link

Sending and receiving specific AT Commands for SPIFriend #10205

Closed mrnoisytiger closed 3 years ago

mrnoisytiger commented 4 years ago

I'm looking to send specific AT commands to the Bluefruit SPI Chip, specifically the AT+FACTORYRESET in a custom keycode. Is there a way that's recommended to do this?

In tmk_core/protocol/lufa/adafruit_ble.cpp, there is:

bool at_command_P(const char *cmd, char *resp, uint16_t resplen, bool verbose) {
    auto cmdbuf = (char *)alloca(strlen_P(cmd) + 1);
    strcpy_P(cmdbuf, cmd);
    return at_command(cmdbuf, resp, resplen, verbose);
}

bool adafruit_ble_enable_keyboard(void) {
    char resbuf[128];

    if (!state.initialized && !ble_init()) {
        return false;
    }

    state.configured = false;

    // Disable command echo
    static const char kEcho[] PROGMEM = "ATE=0";
    // Make the advertised name match the keyboard
    static const char kGapDevName[] PROGMEM = "AT+GAPDEVNAME=" STR(PRODUCT);
    // Turn on keyboard support
    static const char kHidEnOn[] PROGMEM = "AT+BLEHIDEN=1";

    // Adjust intervals to improve latency.  This causes the "central"
    // system (computer/tablet) to poll us every 10-30 ms.  We can't
    // set a smaller value than 10ms, and 30ms seems to be the natural
    // processing time on my macbook.  Keeping it constrained to that
    // feels reasonable to type to.
    static const char kGapIntervals[] PROGMEM = "AT+GAPINTERVALS=10,30,,";

    // Reset the device so that it picks up the above changes
    static const char kATZ[] PROGMEM = "ATZ";

    // Turn down the power level a bit
    static const char  kPower[] PROGMEM             = "AT+BLEPOWERLEVEL=-12";
    static PGM_P const configure_commands[] PROGMEM = {
        kEcho, kGapIntervals, kGapDevName, kHidEnOn, kPower, kATZ,
    };

...

I effectively want to mimic the static const char kXXXp[ PROGMEM = "ATCOMMAND" lines but inside of a custom keycode.

My initial intuition is that I can simply create a function that sets a char array, then runs the at_command_p() function to send it:

char resbuf[48]
static const char kFRST[] PROGMEM = "AT+FACTORYRESET"
at_command_p(kFRST, resbuf, sizeof(resbuf))
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in the next 30 days unless it is tagged properly or other activity occurs. For maintainers: Please label with bug, in progress, on hold, discussion or to do to prevent the issue from being re-flagged.

stale[bot] commented 3 years ago

This issue has been automatically closed because it has not had activity in the last 30 days. If this issue is still valid, re-open the issue and let us know.