Geophysical flows are highly turbulent, and yet embody large-scale coherent structures such as jets and long lived vortices. Understanding how these structures appear and predicting their shape are major theoretical challenges. Equilibrium statistical mechanics is a powerful approach that describes with only a few thermodynamical parameters the long time behavior of the largest scales of those geophysical flows within the inertial limit. This approach has also been proven useful to describe self-organization in weakly forced-dissipated configurations. Previous applications of the theory led to successful description of the Great Red Spot of Jupiter, or of ocean rings and jets [1]. Because of essential theoretical difficulties, all those previous applications were up to now limited to quasi-geostrophic models. Here we generalize the equilibrium statistical mechanics theory to the more comprehensive shallow water system, including inertia-gravity waves and the possibility of energy transfers towards small scales, with the concommittant emergence of a large scale vortical flow [2]. This is a key step towards an understanding of the energy balance of geophysical flows. Using large deviation theory, we compute the entropy of macrostates for the microcanonical measure of the shallow water system. The main prediction of this full statistical mechanics computation is the energy partition between the large scale vortical flow and small scale fluctuations related to inertia-gravity waves. We introduce for that purpose a semi-Lagrangian discrete model of the continuous shallow water system, and compute the corresponding statistical equilibria. We argue that microcanonical equilibrium states of the discrete model in the continuous limit are equilibrium states of the actual shallow water system. We show that the presence of small scale fluctuations selects a subclass of equilibria among the states that were previously computed by phenomenological approaches that were neglecting such fluctuations. We provide explicite computations of the equilibria within the quasi-geostrophic limit (strong rotation limit), taking into account the presence of small scale fluctuations. This allows us to discuss the important role of bottom topography and rotation to sustain a large-scale flow structure. We finally address the possible role of small scale dissipation and shocks within this framework, and geophysical applications of those results. [1] F. Bouchet, A. Venaille Physics Reports 515: 227–295, 2012. [2] A. Renaud, A. Venaille, F. Bouchet. Journal of Statistical Physics, 10.1007/s10955-016-1496-x, 2016